The stored procedures in Server SQL are as follows:
CREATE procedure Pinsertpc
@pcnum int,
@pcname varchar (50),
@pctype int,
@ipaddress varchar (50),
@port int,
@pcid int Output
As
--declare @pcid int
if exists (SELECT * from computertable where pcnum = @pcnum)
Set @pcid =-1
Else
Begin
Insert into computertable (Pcnum, Pcname, Pctype, IpAddress, Port)
VALUES (@pcnum, @pcname, @pctype, @ipaddress, @port)
Select @pcid = scope_identity ()
End
--return @pcid
GO
According to the online search article, "SQL Server stored procedures in QT" is as follows:
Wrote a stored procedure ready to use QT call, database is SQL Server 2000 according to the reference document
The call is the following
Qsqlquery query;
Query.prepare ("Call Insertimgentity (?,?,?,?,?,?,?,?,?,?)");
Query.bindvalue (0,datano);
Query.bindvalue (1,datacorner);
Query.bindvalue (2,datazd);
Query.bindvalue (3,datacommon);
Query.bindvalue (4,imgcode);
Query.bindvalue (5,imgcodez);
Query.bindvalue (6, "PNG");
Query.bindvalue (7,pngimage,qsql::binary);
Query.bindvalue (8, "Goldmap gaoyong Sun");
Query.bindvalue (9,qdatetime::currentdatetime ());
But I can't invoke success under Windows. Debug trace, found that I am debugging the stored procedure is called by exec, so the code is modified as follows, the problem is resolved, the cause of this result may be the database is different.
Query.prepare ("exec insertimgentity?,?,?,?,?,?,?,?,?,?");
Query.bindvalue (0,datano);
Query.bindvalue (1,datacorner);
Query.bindvalue (2,datazd);
Query.bindvalue (3,datacommon);
Query.bindvalue (4,imgcode);
Query.bindvalue (5,imgcodez);
Query.bindvalue (6, "PNG");
Query.bindvalue (7,pngimage,qsql::binary);
Query.bindvalue (8, "Goldmap gaoyong Sun");
Query.bindvalue (9,qdatetime::currentdatetime ());
However, the job needs to have a return value in the stored procedure, or an output parameter that returns the currently inserted ID number. A workaround is obtained through testing. Take the top stored procedure as an example QT has the following code:
BOOL Qtsqlserver::sqlinsertpcdata (qtpcdata* pcData)
{
BOOL Bflag = false;
Qsqlquery query;
Query.prepare ("exec pinsertpc?,?,?,?,?,? Output ");
Query.bindvalue (0, Pcdata->getpcnum ());
Query.bindvalue (1, Pcdata->getpcname ());
Query.bindvalue (2, Pcdata->getpctype ());
Query.bindvalue (3, pcdata->getipaddress ());
Query.bindvalue (4, Pcdata->getport ());
Query.bindvalue (5, 0, qsql::out);
Bflag = Query.exec ();
if (bflag)
{
int PcID = Query.boundvalue (5). ToInt ();
if (PcID < 0)
{
Bflag = false;
}
Else
{
Pcdata->setpcid (PcID);
Bflag = true;
}
}
Else
{
QString str = query.lasterror (). text ();
Qmessagebox::critical (0, Qobject::tr ("Error"), Qobject::tr ("%1"). Arg (str));
}
return bflag;
}
There are some unknown questions ... The output parameter here must be set to be returned in the last parameter of the stored procedure, and must have a decoration of output according to the requirements in server SQL to ensure success.
Question 1: If the stored procedure wants to return as a return value, how to invoke it using QT.
Question 2: Why the output parameter of the stored procedure must be set before the last parameter can get the correct output value, such as to return in the first parameter, how to resolve.
Question 3: Some stored procedures have multiple output parameters, but I test QT only as an output parameter (set to the last parameter) call ... It's a headache for me! The whole of my other output parameters are found in persistent SQL statements ...
Recently seemed quite playful .... To Converge and converge! Hey! The above questions if someone can answer, small very grateful, communicate with each other, learn from each other!
http://cool.worm.blog.163.com/blog/static/6433900620091018103220702/
QT calls a stored procedure in server SQL