LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   ms access like calls (ie openrecordset) to Mysql in c program include database,h (https://www.linuxquestions.org/questions/programming-9/ms-access-like-calls-ie-openrecordset-to-mysql-in-c-program-include-database-h-619528/)

pjlinux100 02-08-2008 01:42 AM

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?

Tinkster 02-08-2008 05:57 PM

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.

sundialsvcs 02-08-2008 07:07 PM

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

pjlinux100 02-09-2008 05:49 PM

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);
}

paulsm4 02-09-2008 10:31 PM

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

Tinkster 02-10-2008 02:28 AM

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

pjlinux100 02-10-2008 06:11 AM

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_point:(10,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

Tinkster 02-10-2008 11:18 AM

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

paulsm4 02-10-2008 12:17 PM

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

pjlinux100 02-10-2008 04:45 PM

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


All times are GMT -5. The time now is 03:46 AM.