LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-08-2008, 01:42 AM   #1
pjlinux100
LQ Newbie
 
Registered: Feb 2008
Posts: 4

Rep: Reputation: 0
ms access like calls (ie openrecordset) to Mysql in c program include database,h


I am migrating a cgi program in c that accesses MySQL 3.22 from Redhat 7to MySQL 5 to latest version of Centos. The c program includes a file database.h. The calls to MySQL include OpenDatabase, OpenRecordset, CloseRecordset. These calls are like Ms Access.

Does anyone know of a library defined by database.h that converts ms access calls to MySQL calls? Any thoughts?

Last edited by pjlinux100; 02-08-2008 at 03:57 PM. Reason: error
 
Old 02-08-2008, 05:57 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Hi,

And welcome to LQ!

I'm not sure what you mean by "like MS Access". Those are rather
generic terms in the database world, and I'd expect to see those
(or similarly named) functions in pretty much any low-level inter-
face to any database product (not that I personally think of access
as such). In light of this I can't see a need for a "conversion
tool for calls".

But maybe I misunderstood you all together? If so please re-phrase
your question.



Cheers,
Tink


P.S.: This thread seems better of in Programming, and I'm moving
it there to give it the exposure it deserves.
 
Old 02-08-2008, 07:07 PM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,636
Blog Entries: 4

Rep: Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933
In the C programming-language, such things would be very hard to come by, because that language does not know about objects.

In the C++ programming-language, and higher-level languages such as Perl, Python, PHP, and Ruby (quite likely all of which are also supported by your Linux installation!), these ways of dealing with a database are quite routine. (Note that Visual Basic syntax is not used.)
 
Old 02-09-2008, 05:49 PM   #4
pjlinux100
LQ Newbie
 
Registered: Feb 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Hi Guys, thanks for the comments. The problem I have is that these calls opendatabase openrecordset etc do not seem to be supported in the Mysql C API. Quite different methods are used. Were these calls changed in later versions of MySQL or am I missing something? The clue is the header file database.h. What does this header file relate to?

I really don't want to rewrite the program because these calls work just fine with the older version of MySQL. I just cannot bring myself to believe that such a radical change would occur in the methods of talking to MySQL.

my c program

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <database.h>

void get_usr_cnt()
{
int i;
char addr1[50];
char *tmp_no;
long lCnt;


OpenDatabase(mydb, NULL, myid, mypw);

strcpy(csql,"DELETE FROM sfhs WHERE id BETWEEN 1000 AND 1100");
OpenRecordset(csql);
CloseRecordset();



new method

#include <mysql.h>
#include <stdio.h>

main() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;

char *server = “localhost”;
char *user = “root”;
char *password = “PASSWORD”; /* set me first */
char *database = “mysql”;

conn = mysql_init(NULL);

/* Connect to database */
if (!mysql_real_connect(conn, server,
user, password, database, 0, NULL, 0)) {
fprintf(stderr, “%s\n“, mysql_error(conn));
exit(1);
}
 
Old 02-09-2008, 10:31 PM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

"OpenRecordset()" and friends are from Microsoft's "DAO" programming API:

http://en.wikipedia.org/wiki/Data_Access_Objects

DAO was primarily designed for use with Visual Basic (although it can be called from C, C++ or just about any other language), and uses ODBC to communicate with the underlying database.

It's successor was "ADO" (which used OleDB to talk to the database), and ADO's successor is ADO.Net (similar name; completely different technology).

All of these Microsoft APIs (DAO, ADO and ADO.Net) were designed primarily for Microsoft programming environments (notably, VB) and Microsoft Windows.

AFAIK, there isn't a corresponding DAO library for Linux. But it should be relatively straightforward to port to either the MySQL API (which will work on Windows or Linux ... but only with MySQL), or a good ODBC library (which will work anywhere):

http://dev.mysql.com/doc/refman/5.0/en/apis.html
http://dev.mysql.com/downloads/connector/odbc/3.51.html
http://www.unixodbc.org/
http://www.linux.com/articles/60185

'Hope that helps .. PSM

Last edited by paulsm4; 02-09-2008 at 10:34 PM.
 
Old 02-10-2008, 02:28 AM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
What I don't get is that he's saying it's MySQL 3 on RedHat using
that stuff, though? Was there a MAJOR change in MySQLs API since?



Cheers,
Tink
 
Old 02-10-2008, 06:11 AM   #7
pjlinux100
LQ Newbie
 
Registered: Feb 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Hi Guys,
Thanks for the advice. This is so close. Again the clues to the api used is database.h and that the api is currently used by the old c program so it must be for linux.

From the c compile output:

__gmon_start__ libmysqlclient.so.6 _DYNAMIC _GLOBAL_OFFSET_TABLE_ _init _fini mysql_connect mysql_select_db mysql_query mysql_store_result mysql_fetch_row mysql_data_seek mysql_escape_string mysql_free_result mysql_close libc.so.6 strcpy printf atol getenv malloc strncasecmp strtol fprintf strcat __deregister_frame_info stdin strstr strncpy strcasecmp strncat fread strcmp sprintf fclose stderr fopen atoi _IO_stdin_used __libc_start_main strlen fputs __register_frame_info free _etext _edata __bss_start _end GLIBC_2.1 GLIBC_2.0.

also
init.c /usr/src/bs/BUILD/glibc-2.1.3/csu/ gcc2_compiled. ../include/libc-symbols.h /usr/src/bs/BUILD/glibc-2.1.3/build-i386-linux/config.h ../include/libintl.h ../intl/libintl.h ../include/features.h ../include/sys/cdefs.h ../misc/sys/cdefs.h /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stddef.h ../include/locale.h ../locale/locale.h lconv:T(10,1)=s48decimal_point10,2)=*(../include/xlocale.h ../sysdeps/unix/sysv/linux/_G_config.h ../sysdeps/unix/sysv/linux/bits/types.h 0,1) ../linuxthreads/sysdeps/pthread/bits/pthreadtypes.h ../sysdeps/unix/sysv/linux/bits/sched.h _IO_stdin_used:G(0,1) GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
and

initfini.c gcc2_compiled. init.c crtstuff.c p.2 __DTOR_LIST__ completed.3 __do_global_dtors_aux __EH_FRAME_BEGIN__ fini_dummy object.8 frame_dummy init_dummy force_to_data __CTOR_LIST__ __do_global_ctors_aux __CTOR_END__ __DTOR_END__ __FRAME_END__ sfhs100.c qs.48 ptr.49 fptr.50 eptr.51 tmp_id atol@@GLIBC_2.0 FieldCount buff3 CloseDatabase mysql_store_result sWhere mysql_fetch_row strncat@@GLIBC_2.0 RecordCount get_usr_cnt ntmp2 _DYNAMIC mysql_data_seek nparam GetFieldN test_msg_id _etext __register_frame_info@@GLIBC_2.0 strcmp@@GLIBC_2.0 wrt_fl m_row _m_update_or_delete _fp_hw m_EOF mysql_connect c2 SetFieldB fprintf@@GLIBC_2.0 getenv@@GLIBC_2.0 buff4 parse_query nstart line_decode sAddr get_auth_info get_msg m_add_flag m_current_query m_binary_data GetField get_blob buff1 usr_nm MovePrev usr_zp m_fields upd_nwisr m_result cin OpenDatabase mysql OpenRecordset _init mysql_select_db malloc@@GLIBC_2.0 mysql_escape_string get_msg_id nlength fread@@GLIBC_2.0 upd_nwisr2 mysql_valid __deregister_frame_info@@GLIBC_2.0 get_cmnty_nws stderr@@GLIBC_2.0 find_param verify_name_type Update m_row_valid mysql_close buff2 _start m_field_lengths CloseRecordset c1 get_urls fputs@@GLIBC_2.0 put_pctr AddNew strstr@@GLIBC_2.0 strlen@@GLIBC_2.0 MoveNext cmsgid get_param ckey new_login_nwisr2 test_login get_msg_cnt SetField strtol@@GLIBC_2.0 __bss_start m_row_tell main read_buffer ntmp1 __libc_start_main@@GLIBC_2.0 sComma ndebug strcat@@GLIBC_2.0 data_start printf@@GLIBC_2.0 upd_cmnty_pg _fini csql ncin mysql_free_result m_update_flag verify_addressee fclose@@GLIBC_2.1 m_result_valid RecordsetEOF npad m_field_values usr_pw verify_name_char clct_adrs MoveLast nadrs_id strcasecmp@@GLIBC_2.0 put_msg atoi@@GLIBC_2.0 mysql_query MoveFirst _edata _GLOBAL_OFFSET_TABLE_ free@@GLIBC_2.0 _end m_fields_valid reset_msg_status line_encode AbsolutePosition strncasecmp@@GLIBC_2.0 stdin@@GLIBC_2.0 strncpy@@GLIBC_2.0 fopen@@GLIBC_2.1 myid _IO_stdin_used new_login_nwisr usr_id Delete Refresh sprintf@@GLIBC_2.0 __data_start new_login_nwis mypw SetFieldN mydb sAnd Edit ctmp __gmon_start__ strcpy@@GLIBC_2.0

Could the api be from any of the components listed? What would be related to database.h?

Thanks and regards

pj
 
Old 02-10-2008, 11:18 AM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
My first impulse now is to tell you to simply look
for that header-file on the system, and see what it
says it belongs to in its comments .... or did you
already?


Cheers,
Tink
 
Old 02-10-2008, 12:17 PM   #9
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
pjlinux100 -

Please let me restate the point I was trying to make:
* "OpenDatabase()" and "OpenRecordset()" were *never* part of any mysql library. They're from Microsoft's DAO. DAO supports many different databases - but only on Windows. DAO is now obsolete - even in Microsoft-Land.

* "mysql_init()" and "mysql_fetch_row()" are from the MySQL library. They work on Linux or Windows; they're probably very similar (identical?) between MySQL 3 and MySQL 5.

* "database.h" is a Microsoft header for the Microsoft DAO library.
It can be found in the Microsoft directory "c:\Program files\<Visual Studio>\<vcxx>\Include". It cannot be used outside of Visual Studio.

So basically, your choices are:
a) Find a DAO library for Linux
... or ...
b) Port the DAO code to a different library

I think "b)" is probably easiest, and probably not terribly difficult.

IMHO .. PSM
 
Old 02-10-2008, 04:45 PM   #10
pjlinux100
LQ Newbie
 
Registered: Feb 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Many thanks for the contributions. Tink, unfortunately I do not have the original development environment.

PSM, 1 will pursue option (a) first for the fundamental reason that it must exist because it was used in the existing c on linux. I suspect it was used in this c program because the programmer was comfortable with those data base constructs. Maybe that need still exists.

Cheers

pj
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mySQL deny user access to database blizunt7 Programming 3 10-10-2007 09:34 AM
mysql - can't access mysql database as root yogaboy Linux - Software 5 12-28-2006 06:58 AM
Need database program to access MySQL apachedude Linux - Software 12 01-03-2006 10:50 AM
How to interact with MYSQL database from within perl program Bassam Programming 5 02-26-2004 05:00 PM
MySQL Cannot Access Database ChineseElite Linux - General 13 11-27-2002 08:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration