UPDATE 2006/01/15: have all results processing fine so C wrap is completely functional. functions defined in the C wrap are:
Extern "C"
Function bmx_mysql_init:Int()
Function bmx_mysql_close(MYSQL:Int)
Function bmx_mysql_errno:Int(MYSQL:Int)
Function bmx_mysql_error:Byte Ptr(MYSQL:Int)
Function bmx_mysql_connect:Int(MYSQL:Int,host$z,user$z,passwd$z,db$z,port:Int=3306,unix_socket$z=Null,clientflag:Int=0)
Function bmx_mysql_select_db:Int(MYSQL:Int,db$z) ' returns true/false
Function bmx_mysql_real_query:Int(MYSQL:Int,qry$z,length:Long) ' returns true/false
Function bmx_mysql_affected_rows:Int(MYSQL:Int)
Function bmx_mysql_num_rows:Int(MYSQL_RES:Int)
Function bmx_mysql_num_fields:Int(MYSQL_RES:Int)
Function bmx_mysql_field_length:Int(MYSQL_RES:Int,fieldnr:Int)
Function bmx_mysql_store_result:Int(MYSQL:Int) ' returns MYSQL_RES*
Function bmx_mysql_use_result:Int(MYSQL:Int) ' returns MYSQL_RES*
Function bmx_mysql_fetch_row:Byte Ptr Ptr(MYSQL_RES:Int) ' returns MYSQL_ROW (array of char*)
Function bmx_mysql_eof:Int(MYSQL_RES:Int) ' returns true/false
Function bmx_mysql_insert_id:Int(MYSQL:Int)
Function bmx_mysql_free_result(MYSQL_RES:Int)
Function bmx_mysql_real_escape_string:Int(MYSQL:Int,strTo:Byte Ptr,strFrom:Byte Ptr,fromLength:Int) ' returns length placed in To
Function bmx_mysql_field_name:Byte Ptr(MYSQL_RES:Int,fieldnr:Int)
Function bmx_mysql_field_value:Byte Ptr(MYSQL_ROW:Byte Ptr Ptr,fieldnr:Int)
Function bmx_mysql_isfieldnull:Int(MYSQL_ROW:Byte Ptr Ptr,fieldnr:Int) ' returns true/false
EndExtern
i am now working on getting some types created that will make accessing MySQL pretty easy for simple functionality. i plan to break this out into 2 modules: Pub.MySQL and Pub.ISQLDB. Pub.ISQLDB is meant to be an interface set of types so that there can be a universal interface for different SQL database back ends. for example, there would be the same set of the methods to access MySQL, SQLLite, and PostgreSQL so to change backends would be trivial as long as you used the SQLDB interface to access functionality. type ISQLDB interface types i have defined so far are:
' interface for an SQL database connection
Type ISQLDB
' get/set properties for connection settings
Method setHost(host:String) Abstract
Method getHost:String() Abstract
Method setDB(database:String) Abstract
Method getDB:String() Abstract
Method setUsername(username:String) Abstract
Method getUsername:String() Abstract
Method setPassword(password:String) Abstract
Method getPassword:String() Abstract
Method setPort(port:Int) Abstract
Method getPort:Int() Abstract
Method setFlags(flags:Int=0) Abstract
Method getFlags:Int() Abstract
Method getError:Int() Abstract
Method getErrorMsg:String() Abstract
' methods for working the connection
Method openConnection:Int() Abstract ' returns true/false
Method closeConnection() Abstract
Method queryDB:ISQLResult(query:String,bPrefetch:Int=True,handler:IOnResultEventHandler=Null) Abstract
Method selectDB:Int(database:String) Abstract
EndType
Type IOnResultEventHandler Abstract
Method OnResult() Abstract
EndType
' contains info on the result of a query
Type ISQLResult
Method getConnection:ISQLDB() Abstract
Method getQuery:String() Abstract ' the query that was processed
Method getError:Int() Abstract
Method getErrorMsg:String() Abstract
Method getSuccess:Int() Abstract
Method getNumRows:Int() Abstract
Method getNumCols:Int() Abstract
Method getColName:String(col:Int) Abstract
Method getColWidth:Int(col:Int) Abstract
Method getVal:String(row:Int,col:Int) Abstract
Method getValByName:String(row:Int,col:String) Abstract
Method getIntVal:Int(row:Int,col:Int) Abstract
Method getIntValByName:Int(row:Int,col:String) Abstract
Method getLongVal:Long(row:Int,col:Int) Abstract
Method getLongValByName:Long(row:Int,col:String) Abstract
Method getFloatVal:Float(row:Int,col:Int) Abstract
Method getFloatValByName:Float(row:Int,col:String) Abstract
Method getDoubleVal:Float(row:Int,col:Int) Abstract
Method getDoubleValByName:Float(row:Int,col:String) Abstract
Method getInsertId:Int() Abstract
EndType
the MySQL version of ISQLDB looks like:
Type MySQLDB Extends ISQLDB
Field _host:String
Field _username:String
Field _password:String
Field _port:Int=3306
Field _flags:Int=0
Field _conn:Int ' MYSQL*
Field _db:String
Field _unixsocket:String=Null
Field _lastErrMsg:String
Field _lastErr:Int
Function create:MySQLDB(bConnect:Int,host:String,user:String,passwd:String,db:String=Null,port:Int=3306,unix_socket:String=Null,clientflags:Int=0)
Local retval:MYSQLDB=New MYSQLDB
retval.setHost(host)
retval.setUsername(user)
retval.setPassword(passwd)
retval.setDB(db)
retval.setPort(port)
retval.setUnixSocket(unix_socket)
retval.setFlags(clientflags)
If bConnect Then retval.openConnection()
Return retval
EndFunction
' get/set properties for connection settings
Method setHost(host:String)
_host=host
EndMethod
Method getHost:String()
Return _host
EndMethod
Method setDB(database:String)
_db=database
EndMethod
Method getDB:String()
Return _db
EndMethod
Method setUsername(username:String)
_username=username
EndMethod
Method getUsername:String()
Return _username
EndMethod
Method setPassword(password:String)
_password=password
EndMethod
Method getPassword:String()
Return _password
EndMethod
Method setPort(port:Int=3306)
_port=port
EndMethod
Method getPort:Int()
Return _port
EndMethod
Method setFlags(flags:Int=0)
_flags=flags
EndMethod
Method getFlags:Int()
Return _flags
EndMethod
Method setUnixSocket(unix_socket:String=Null)
_unixsocket=unix_socket
EndMethod
Method getUnixSocket:String()
Return _unixsocket
EndMethod
' methods for working the connection
Method openConnection:Int()
Local retval:Int=False
_conn=bmx_mysql_init()
If _conn
If Not bmx_mysql_connect(_conn,_host,_username,_password,_db,_port,_unixsocket,_flags)
FillError() ' error, fill with info from MySQL
EndIf
Else
' error, but not loggable because no valid connection
FillError(ERR_INIT_FAIL,"Failed to intialize MySQL client library")
EndIf
Return retval
EndMethod
Method closeConnection()
If _conn Then bmx_mysql_close(_conn)
FillError() ' clear/fill the error info
EndMethod
Method Delete()
closeConnection() ' close out if there is an open connection
EndMethod
Method selectDB:Int(database:String)
Local retval:Int=False
retval=bmx_mysql_select_db(_conn,database)
If retval Then setDB(database)
FillError() ' clear/fill the error info
Return retval
EndMethod
Method queryDB:ISQLResult(query:String,bPrefetch:Int=True,handler:IOnResultEventHandler=Null)
EndMethod
Method FillError(errno:Int=-9999,errmsg:String=Null)
If errno=-9999 Then _lastErr=bmx_mysql_errno(_conn) Else _lastErr=errno
If Not errmsg Then _lastErrMsg=String.FromCString(bmx_mysql_error(_conn)) Else _lastErrMsg=errmsg
EndMethod
Method getError:Int()
Return _lastErr
EndMethod
Method getErrorMsg:String()
Return _lastErrMsg
EndMethod
EndType
feel like im rambling here so back to work. looks like im on target for a release of this weekend.