List:General Discussion« Previous MessageNext Message »
From:Ed Carp Date:March 14 1999 12:33pm
Subject:Re: VisualBASIC API
View as plain text  
>well i was wandering if someone have written VisualBASIC API for
>MySQL... If doesn't , i intend to make it by myself - if someone did i
>would apretiate if he/she wants to share the code with us so it would
>save my time...
>Also, any examples of using that API are welcome! :)

I've been working on a C API that looks sort of like VB, though the idea
behind MySQL and VB are quite different.  It is possible, for example, to
walk through a recordset like:

(VB code):

Dim MyDB as Database, MyRS as Recordset

Set MyDB = OpenDatabase(dbname)
Set MyRS = MyDB.OpenRecordset(query)
While Not MyRS.EOF
    Debug.Print MyRS.Fields("Field1")
Set MyRS = Nothing
Set MyDB = Nothing

The equivalent MySQL C API wrapper code would look like:

#include "database.h"

[define variables]

OpenDatabase(dbname, NULL, NULL , NULL);
while (m_EOF == FALSE)

Due to the design of the MySQL API, there are some significant problems with
this type of approach.  For example, there is no way to directly update or
delete a row in a recordset.  I've solved the problem for update:

OpenDatabase(dbname, NULL, NULL , NULL);
while (m_EOF == FALSE)
   Edit(); /* AddNew() is also supported */
   SetField("Field1", new_value);

... and I've got a partial solution for delete:

OpenDatabase(dbnaem, NULL, NULL , NULL);
while (RecordsetEOF() == FALSE)
   if (strcmp(GetField("Field1"), search_field) == 0) Delete(table);

...but the problem with delete is a little more tricky - it's a snap if at
least one of the fields is unique, but if there are no unique fields, then
ALL records matching the criteria are deleted.  This is at variance with the
concept of a view or recordset, where one can delete individual records,
regardless if they're duplicates or not. I think I can work around this by
doing a "DELETE FROM table WHERE field1='blah' AND field2='blah' LIMIT 1" -
this syntax is supported in 3.22.19b.

The verbs I have implemented so far (I've added a couple of my own):

OpenDatabase (db, host, name, pass)
OpenRecordset (query)
MoveNext ()
MovePrev ()
MoveLast ()
MoveFirst ()
GetField (fieldname)
GetFieldN (n)
SetField (fieldname, value)
SetFieldN (fieldnum, value)
SetFieldB (fieldname, value) /* convert to binary first */
Update (table)
AddNew ()
Edit ()
CloseRecordset ()
CloseDatabase ()
RecordCount ()
FieldCount ()
AbsolutePosition ()
Refresh () /* refresh the recordset */
RecordsetEOF ()

At the moment, it only supports one recordset open at a time, but I'm
planning on changing that in the very near future.

If folks want the code, I can put it up for FTP or on my web page
somewhere - I've been planning on releasing it in the next week with several
sample programs, to show people how to use the wrapper code.  Email me
privately, please - if there's enough interest, I'll post the URL here.
Please remember that this is ALPHA code - I've got it running in a number of
programs here that run 24 hours a day, and I haven't seen any problems, but
there's no guarantees - you get what you pay for ;)
Ed Carp, N7EKG - erc@stripped - 9403672744@stripped for URGENT
messages only!

"There are three kinds of lies: lies, damn lies .. and then there's Bill

VisualBASIC APIleka14 Mar
Re: VisualBASIC APIEd Carp14 Mar
  • Re: VisualBASIC APIleka14 Mar
Re: VisualBASIC APIEd Carp14 Mar
  • Re: VisualBASIC APIleka14 Mar
Re: VisualBASIC APIEd Carp14 Mar
Re: VisualBASIC APIEd Carp14 Mar