~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
since you are going to rewrite the program you might as well use ODBC to make it more generic to any database -- next time the database changes you won't have to change the c code very much. google for "odbc" and you will find lots of c++ classes and other C function libraries.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
thanks for you reply in advance.
what I want is just "how could I implement the CURSOR by Mysql C API?"
our project is only work in C(the entire system is compiled by gcc), so I didn't know how ODBC could work here also(I never used ODBC before).
ODBC can be accessed via several languages -- C, C++, java, perl, php, vb, and probably many others.
You probably don't need to set up a cursor at all. ODBC contains functions that will retrieve the result set one row at a time. All you have to do is put the SELECT statement in a C string, send it to the database using ODBC function, then create a loop to call ODBC fetch() until fetch() tells your program there is no more data.
I realize you want just a "quick and dirty" fix for your problem, but often that is not a good long-term solution. If this project is for where you work then it will be to your advantage, and your company's advantage, for you to spend a few days to learn ODBC. It doesn't reallyreplace the code you have now but is a different way of accessing databases. ODBC still uses SQL language, but unlike the code you have now ODBC will send it to the database server to be processed.
[edit] Here is a good C tutorial.[/edit]
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343