954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Pro*C to Mysql C API

hi,
 In recently, I have a mission for porting a source code from Pro*C. And the database is changed from Oracle to Mysql. The part of original source code(Pro*C) is shown below:

char i_id_no[13+1];
char accn_name[16+1], account[7+1], b_no[20+1], code_type[1];
int ii;

:
:
EXEC SQL DECLARE cursor_1 CURSOR FOR
SELECT accn_name, account, b_no, code_type
FROM ACCOUNTINFO
WHERE id_no = :i_id_no;
EXEC SQL OPEN cursor_1;

for(ii=0;; )
{
EXEC SQL FETCH cursor_1
INTO :accn_name, :account, :b_no, :code_type;
if (sqlca.sqlcode == 1403)
break;
:
:
}
:
:
EXEC SQL CLOSE cursor_1;

How could I make the same functions by mysql C API ?

ps.
compiler: gcc
os : RH Linux AS 4.0
Mysql: 5.0

seanlo
Newbie Poster
3 posts since Sep 2006
Reputation Points: 22
Solved Threads: 0
 

Dont know what exactly you want but if you want some tuts on interfacign MySQL and C you can visit some of the links given below:

http://www.tol.it/doc/MySQL/
http://dev.mysql.com/doc/refman/5.0/en/c.html

Hope it helped, bye

~s.o.s~
Failure as a human
Administrator
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
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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).

seanlo
Newbie Poster
3 posts since Sep 2006
Reputation Points: 22
Solved Threads: 0
 

Since i dont know a lot about all this i cant say anything definate but here are some of the links realted to CURSORS and Oracle and mysql.

http://www.sqlapi.com/Examples/refcursors.cpp
http://dev.mysql.com/doc/refman/5.1/en/c-api-function-overview.html

And also you will have to read the links posted by me in the previous post to get a better understanding since not many people have attempted this thing and you are very much on your own.

Best of luck, bye.

~s.o.s~
Failure as a human
Administrator
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
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Thank you all about told me the solution to fix my problem , I will try to solve the problem by your way, also ODBC.
maybe mysql C API will be the better way to fix it (because of performance), but ODBC still is a seconary solution(maybe a easier way). I will try it anyway

Thank you guys.

seanlo
Newbie Poster
3 posts since Sep 2006
Reputation Points: 22
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You