I am working on a client interface that can connect to any DB by passing the desired query in an input field and the server side (coded in C and using sql.h), parses this query and returns content in JSON format. I am able to accomplish this easily by using Select * from tablename query as i am able to get the number of rows using the count(*) query and i use this with a for loop to print my JSON into a buffer. How am i to accomplish the same for anyother query?
I read up somewhere that row-wise binding might help but whats the logic behind parsing a resultset into a json format? (under the assumption that i need the data in a row-wise format. example : {"Records" : [["col heading 1", "col heading 2", "col heading 3"], ["row content 1", "row content 2", "row content 3"]...]})
ODBC only offers a way (
SQLRowCount) to find out the number of affected rows forUPDATE/DELETE/INSERTStatements – see http://msdn.microsoft.com/en-us/library/ms711835%28v=VS.85%29.aspx…IF you want to find out the number of rows of a
SELECTyou either execute the query a second time asSELECT COUNT(*)OR you just loop over the result set and count the rows ODBC delivers…see http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/6fe5403d-900c-4b07-9d00-1f42731b5602
and How to Get The Count or The Number Of Rows In A Result Set In PHP using ODBC Connection?
NOTE: Although the second link mentions PHP, the answer is language-agnostic since the cause of the behaviour lies in the ODBC standard and the used ODBC driver.