hi there!!
I am having problems on porting a sql app from qt3 to qt4.
I must tell u that i dont know SQL and i have not used QSql before.. i was porting an application to qt 4 so i got some knowlegde of SQL and qt's SQL module.
the application connects to a MS SQL server 7.0 database on network (QODBC).
i call QSqlDataBase::addDatabase("QODBC", "myID"); and all other initializing functions and the
database is connnected succesfully.
now i can execute simple SQL queries without any problem.
The problem is on calling the stored procedure on the database.
i made a small, very simple stored procedure whose code is ->
CREATE proc GetTransactionTest
@pin_type nvarchar(20),
@pou_year numeric(4) output,
@pou_text nvarchar(2000) output
AS
begin
----- Initialize out parameters ----
SELECT @pou_trans_year=2007
SELECT @pou_trans_text="Some long text from record"
------------------------------------
end
CREATE proc GetTransactionTest
@pin_type nvarchar(20),
@pou_year numeric(4) output,
@pou_text nvarchar(2000) output
as
begin
----- Initialize out parameters ----
select @pou_trans_year=2007
select @pou_trans_text="Some long text from record"
------------------------------------
end
To copy to clipboard, switch view to plain text mode
this procedure takes one input "pin_type" and two output parameters viz "pou_year",
"pou_text".
now i have the sqlquery code in my app like this ->
void MyClass::callDBprocedure() {
//This commented line works fine, that means the connection is correct.
//query->exec("SELECT something FROM anything")
//problem lines
query->prepare("{call GetTransactionTest(?,?,?)}");
type="MY_TYPE" //QString
year=0; //int
text.fill(' ',2000); //QString
query.bindValue(0,type);
query.bindValue(1,year,QSql::Out);
query.bindValue(2,text,QSql::Out);
if(query->exec())
{
//success
}
else
{
//Always gets here.
}
}
void MyClass::callDBprocedure() {
QSqlQuery *query=new QSqlQuery(database);
//This commented line works fine, that means the connection is correct.
//query->exec("SELECT something FROM anything")
//problem lines
query->prepare("{call GetTransactionTest(?,?,?)}");
type="MY_TYPE" //QString
year=0; //int
text.fill(' ',2000); //QString
query.bindValue(0,type);
query.bindValue(1,year,QSql::Out);
query.bindValue(2,text,QSql::Out);
if(query->exec())
{
//success
}
else
{
//Always gets here.
}
}
To copy to clipboard, switch view to plain text mode
Because our output parameter needs 2000 charecters i have to do "text.fill(' ',2000) or text.resize(2000)", but
as i resize this to any length greater than 127 the query fails. and lastError() returns the following string
[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionRead(recv()).[Microsoft][ODBC SQL Server Driver][DBNETLIB]General Network
error. Check your network documentation. QODBC3: Unable to execute statement.
the query succeeds when i write text.fill(' ', 127) (any value less then 127).
All of this was working fine on the same network with same stored procedure in my Qt3.3.6 application.
please.. help... has anyone had this kind of problem before??
Bookmarks