How to call SQL function from Qt -
i have function returns integer. can't figure how call function in qt.
create function islastappversion( @currentversion nvarchar(10), @appcode nvarchar(128), @serial nvarchar(128)) returns int begin declare @ret int select @ret = case when @currentversion = (select *from getapplastversion(@appcode,@serial)) 1 else 0 end return @ret end
from sql server call this:
declare @i int exec @i = dbo.islastappversion @currentversion = '2.1',@appcode = '33fdd5f4-e24b-11e3-a375-82687f4fc15c',@serial='14jt-cf3c-24b1-c1e3' print @i
how qt? tried. not working
qstring dbconnection::islastversion(qstring version, qstring appcode, qstring serialno){ qsqlquery query; qstring result; qstring connectionstring = connection.arg(servername).arg(dbname); qsqldatabase db = qsqldatabase::adddatabase("qodbc"); db.setdatabasename(connectionstring); if (db.open()) { qdebug() << "opened"; query = db.exec("islastappversion('" + version + "','" + appcode + "','" + serialno + "');"); while(query.next()){ result = query.record().value(0).tostring(); qdebug() << "result la functie last version: " << result; } db.close(); } else { qdebug() << "error = " << db.lasterror().text(); } db.close(); return result; }
since function called via select statement, call sql server's built-in functions (getdate(), sum(), count())
in case like....
select dbo.islastappversion('2.1' ,'33fdd5f4-e24b-11e3-a375-82687f4fc15c' ,'14jt-cf3c-24b1-c1e3')
or if want store returned value variable this...
declare @i int; select @i = dbo.islastappversion('2.1' ,'33fdd5f4-e24b-11e3-a375-82687f4fc15c' ,'14jt-cf3c-24b1-c1e3') print @i
note
also in function definition have following line
when @currentversion = (select *from getapplastversion(@appcode,@serial))
i believe getapplastversion table-values functions. if function returning multiple columns back, need select 1 1 column select statement. if there chance function can return multiple rows make sure use top 1
clause in select statement, comparing results returned function scalar value.
so need make sure function returns single value when called , comparing single value @currentversion
variable.
Comments
Post a Comment