Page 1 of 2

[Crossplatform] MySQL Wrapper

Posted: Tue Oct 30, 2007 2:46 pm
by Thalius
One of my projects i ve been using Flype's MYSQL Lib ( and am pretty happy with it ) but now came the question about a Linuxport of this project. So i had to whip me some wrapping functions around. Figured ill extend it a bit and post here. I didnt want to use ODBC because a. i would have to have to rewrite alot of code in the Project and b. the gann thing broke again as i upgraded to Susi 10.3 :| - well, at least this one should even run on mac :)


Code: Select all

; MySQL 5 DLL-Wrapper Include - Version: 0.2b
; OS: Linux / Windows / AmigaOS / MacOSX ? ( can somone test this ? )
; Author: Marius Eckardt (Thalius) 
; Syntaxcompatible & based on LibMySQL by Flype
; Last Changes: 29.10.2007
;
; Inspired by Flype's Userlib for Windows - i just needed a Version that runs under Linux aswell.
; There could have been alot of more checks/wraps, but in favor of speed and compatibility with Flype's
; Userlib i kept the Syntax the same.
;
; Requirements ( Version 5x of ):
; Linux  : libmysqlclient.so  - ( installed with "mysql-shared" Pakages )
; MacOSX : libmysqlclient.so
; Windows: libmysql.dll 
; AmigaOS: mysqlclient.library
;
; ToDo:
;  - Bugfixes ! ( getting used to Prototype's ... ;)
;  - Descriptions / Examples
;  - stmt functions
; -----------------------------------------------------------------------------------------------

;- Konstants
#MySQLLib = 0

;- OS Check
CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Windows
    MysqlDllFilename$ = "libmysql.dll"
  CompilerCase #PB_OS_Linux
    MysqlDllFilename$ = "libmysqlclient.so"
  CompilerCase #PB_OS_MacOS
    MysqlDllFilename$ = "libmysqlclient.so"
  CompilerCase #PB_OS_AmigaOS
    MysqlDllFilename$ = "mysqlclient.library"
CompilerEndSelect

;- Initialization / OpenDLL
; Macro: InitMySQL() to initialize the MySQL DLL ( call me just once! ) 
Macro InitMySQL()

;- Structures
Structure MYSQL
EndStructure
Structure MYSQL_RES
EndStructure
Structure MYSQL_BIND
EndStructure
Structure MYSQL_STMT
EndStructure

Structure MYSQL_ROW
  field.s[255]
EndStructure
Structure MYSQL_FIELD
  name.s
  org_name.s
  table.s
  org_table.s
  db.s
  catalog.s
  def.s
  length.l
  max_length.l
  name_length.l
  org_name_length.l
  table_length.l
  org_table_length.l
  db_length.l
  catalog_length.l
  def_length.l
  flags.l
  decimals.l
  charset_nr.l
  type.l
EndStructure
Structure MY_CHARSET_INFO
  number.l
  state.l
  csname.s
  name.s
  Comment.s
  dir.s
  mbminlen.l
  mbmaxlen.l
EndStructure

If OpenLibrary(#MySQLLib, MysqlDllFilename$)
  If IsLibrary(#MySQLLib)
  
  ; ** Start Prototypes **
  
  ; Function : mysql_get_client_info()
  ; Usage    : PeekS(mysql_get_client_info())
  ; Desc     : Returns Pointer to Version STRING of Mysql Client
  PrototypeC.l PB_mysql_get_client_info() : Global mysql_get_client_info.PB_mysql_get_client_info = GetFunction(#MySQLLib,"mysql_get_client_info")
  
  ; Function : mysql_get_client_version()
  ; Usage    : Result.l = mysql_get_client_version()
  ; Desc     : Returns Versionnumber as LONG of Mysql Client
  PrototypeC.l PB_mysql_get_client_version() : Global mysql_get_client_version.PB_mysql_get_client_version = GetFunction(#MySQLLib,"mysql_get_client_version")
  
  ; Function : mysql_errno()
  ; Usage    : Result.l = mysql_get_client_info(*MySQLHandle)
  ; Desc     : Returns Error No as LONG
  PrototypeC.l PB_mysql_errno(*mysql.MYSQL) : Global mysql_errno.PB_mysql_errno = GetFunction(#MySQLLib,"mysql_errno")
  
  ; Function : mysql_init()
  ; Usage    : *MySQLHandle = mysql_init(#Null)
  ; Desc     : Returns MySQL DB Handle as LONG
  PrototypeC.l PB_mysql_init(*mysql.MYSQL) : Global mysql_init.PB_mysql_init = GetFunction(#MySQLLib,"mysql_init")
  
  ; Function : mysql_real_connect(*mysql.MYSQL,host.s,user.s,passwd.s,db.s,port.l,unix_socket.s,client_flag.l)
  ; Usage    : Result.l = mysql_real_connect(*mysql.MYSQL,host.s,user.s,passwd.s,db.s,port.l,unix_socket.s,client_flag.l)
  ; Desc     : 
  PrototypeC.l PB_mysql_real_connect(*mysql.MYSQL,host.s,user.s,passwd.s,db.s,port.l,unix_socket.s,client_flag.l) :  mysql_real_connect.PB_mysql_real_connect = GetFunction(#MySQLLib,"mysql_real_connect")
  
  ; Function : mysql_get_parameters()
  ; Usage    : debug Hex(mysql_get_parameters())
  ; Desc     : 
  PrototypeC.l PB_mysql_get_parameters() : Global mysql_get_parameters.PB_mysql_get_parameters = GetFunction(#MySQLLib,"mysql_get_parameters")
  
  ; Function : mysql_sqlstate()
  ; Usage    : State.s = PeekS(mysql_sqlstate(*MySQLHandle))
  ; Desc     : 
  PrototypeC.l PB_mysql_sqlstate(*mysql.MYSQL) : Global mysql_sqlstate.PB_mysql_sqlstate = GetFunction(#MySQLLib,"mysql_sqlstate")
  
  ; Function : mysql_error()
  ; Usage    : PeekS(mysql_error(*MySQLHandle))
  ; Desc     : Returns Pointer as LONG to ErrormessageString 
  PrototypeC.l PB_mysql_error(*mysql.MYSQL) : Global mysql_error.PB_mysql_error = GetFunction(#MySQLLib,"mysql_error")
  
  ; Function : mysql_get_server_version()
  ; Usage    : Result.l = mysql_get_server_version(*MySQLHandle)
  ; Desc     : Returns LONG from ServerVersion
  PrototypeC.l PB_mysql_get_server_version(*mysql.MYSQL) : Global mysql_get_server_version.PB_mysql_get_server_version = GetFunction(#MySQLLib,"mysql_get_server_version")
  
  ; Function : mysql_get_server_info()
  ; Usage    : PeekS(mysql_get_server_info(*MySQLHandle))
  ; Desc     : Returns Pointer as LONG to ServerInfoString 
  PrototypeC.l PB_mysql_get_server_info(*mysql.MYSQL) : Global mysql_get_server_info.PB_mysql_get_server_info = GetFunction(#MySQLLib,"mysql_get_server_info")
  
  ; Function : mysql_get_host_info()
  ; Usage    : PeekS(mysql_get_host_info(*MySQLHandle))
  ; Desc     : Returns Pointer as LONG to HostInfoString / Connectioninfo
  PrototypeC.l PB_mysql_get_host_info(*mysql.MYSQL) : Global mysql_get_host_info.PB_mysql_get_host_info = GetFunction(#MySQLLib,"mysql_get_host_info")
  
  ; Function : mysql_select_db()
  ; Usage    : mysql_select_db(*MySQLHandle, Databasename.s)
  ; Desc     : Selects current Database
  PrototypeC.l PB_mysql_select_db(*mysql.MYSQL, Databasename.s) : Global mysql_select_db.PB_mysql_select_db = GetFunction(#MySQLLib,"mysql_select_db")
  
  ; Function : mysql_get_proto_info()
  ; Usage    : Result.l = mysql_get_proto_info(*MySQLHandle))
  ; Desc     : 
  PrototypeC.l PB_mysql_get_proto_info(*mysql.MYSQL) : Global mysql_get_proto_info.PB_mysql_get_proto_info = GetFunction(#MySQLLib,"mysql_get_proto_info")
  
  ; Function : mysql_info()
  ; Usage    : Result.l = mysql_info(*MySQLHandle))
  ; Desc     : 
  PrototypeC.l PB_mysql_info(*mysql.MYSQL) : Global mysql_info.PB_mysql_info = GetFunction(#MySQLLib,"mysql_info")
  
  ; Function : mysql_insert_id()
  ; Usage    : Result.l = mysql_insert_id(*MySQLHandle))
  ; Desc     : Returns Inserted ID as LONG
  PrototypeC.l PB_mysql_insert_id(*mysql.MYSQL) : Global mysql_insert_id.PB_mysql_insert_id = GetFunction(#MySQLLib,"mysql_insert_id")
  
  ; Function : mysql_affected_rows()
  ; Usage    : Result.l = mysql_affected_rows(*MySQLHandle))
  ; Desc     : 
  PrototypeC.l PB_mysql_affected_rows(*mysql.MYSQL) : Global mysql_affected_rows.PB_mysql_affected_rows = GetFunction(#MySQLLib,"mysql_affected_rows")
  
  ; Function : mysql_autocommit()
  ; Usage    : mysql_autocommit(*MySQLHandle,#Bool) ; #True / #False
  ; Desc     : 
  PrototypeC.l PB_mysql_autocommit(*mysql.MYSQL,*mode.Byte) : Global mysql_autocommit.PB_mysql_autocommit = GetFunction(#MySQLLib,"mysql_autocommit")
  
  ; Function : mysql_character_set_name()
  ; Usage    : mysql_character_set_name(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_character_set_name(*mysql.MYSQL) : Global mysql_character_set_name.PB_mysql_character_set_name = GetFunction(#MySQLLib,"mysql_character_set_name")
  
  ; Function : mysql_close()
  ; Usage    : mysql_close(*MySQLHandle) 
  ; Desc     : Closes the MySQL Connection
  PrototypeC.l PB_mysql_close(*mysql.MYSQL) : Global mysql_close.PB_mysql_close = GetFunction(#MySQLLib,"mysql_close")
  
  ; Function : mysql_commit()
  ; Usage    : mysql_commit(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_commit(*mysql.MYSQL) : Global mysql_commit.PB_mysql_commit = GetFunction(#MySQLLib,"mysql_commit")
  
  ; Function : mysql_debug()
  ; Usage    : mysql_debug(DebugString.s) 
  ; Desc     : 
  PrototypeC.l PB_mysql_debug(DebugString.s) : Global mysql_debug.PB_mysql_debug = GetFunction(#MySQLLib,"mysql_debug")
  
  ; Function : mysql_disable_reads_from_master()
  ; Usage    : mysql_disable_reads_from_master(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_disable_reads_from_master(*mysql.MYSQL) : Global mysql_disable_reads_from_master.PB_mysql_disable_reads_from_master = GetFunction(#MySQLLib,"mysql_disable_reads_from_master")
  
  ; Function : mysql_disable_rpl_parse()
  ; Usage    : mysql_disable_rpl_parse(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_disable_rpl_parse(*mysql.MYSQL) : Global mysql_disable_rpl_parse.PB_mysql_disable_rpl_parse = GetFunction(#MySQLLib,"mysql_disable_rpl_parse")
  
  ; Function : mysql_dumPB_debug_info()
  ; Usage    : mysql_dumPB_debug_info(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_dumPB_debug_info(*mysql.MYSQL) : Global mysql_dumPB_debug_info.PB_mysql_dumPB_debug_info = GetFunction(#MySQLLib,"mysql_dumPB_debug_info")
  
  ; Function : mysql_embedded()
  ; Usage    : mysql_embedded() 
  ; Desc     : 
  PrototypeC.l PB_mysql_embedded() : Global mysql_embedded.PB_mysql_embedded = GetFunction(#MySQLLib,"mysql_embedded")
  
  ; Function : mysql_enable_reads_from_master()
  ; Usage    : mysql_enable_reads_from_master(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_enable_reads_from_master(*mysql.MYSQL) : Global mysql_enable_reads_from_master.PB_mysql_enable_reads_from_master = GetFunction(#MySQLLib,"mysql_enable_reads_from_master")
  
  ; Function : mysql_enable_rpl_parse()
  ; Usage    : mysql_enable_rpl_parse(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_enable_rpl_parse(*mysql.MYSQL) : Global mysql_enable_rpl_parse.PB_mysql_enable_rpl_parse = GetFunction(#MySQLLib,"mysql_enable_rpl_parse")
  
  ; Function : mysql_field_count()
  ; Usage    : mysql_field_count(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_field_count(*mysql.MYSQL) : Global mysql_field_count.PB_mysql_field_count = GetFunction(#MySQLLib,"mysql_field_count")
  
  ; Function : mysql_library_end()
  ; Usage    : mysql_library_end(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_library_end(*mysql.MYSQL) : Global mysql_library_end.PB_mysql_library_end = GetFunction(#MySQLLib,"mysql_library_end")
  
  ; Function : mysql_list_processes()
  ; Usage    : mysql_list_processes(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_list_processes(*mysql.MYSQL) : Global mysql_list_processes.PB_mysql_list_processes = GetFunction(#MySQLLib,"mysql_list_processes")
  
  ; Function : mysql_more_results()
  ; Usage    : mysql_more_results(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_more_results(*mysql.MYSQL) : Global mysql_more_results.PB_mysql_more_results = GetFunction(#MySQLLib,"mysql_more_results")
  
  ; Function : mysql_next_result()
  ; Usage    : mysql_next_result(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_next_result(*mysql.MYSQL) : Global mysql_next_result.PB_mysql_next_result = GetFunction(#MySQLLib,"mysql_next_result")
  
  ; Function : mysql_ping()
  ; Usage    : mysql_ping(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_ping(*mysql.MYSQL) : Global mysql_ping.PB_mysql_ping = GetFunction(#MySQLLib,"mysql_ping")
  
  ; Function : mysql_read_query_result()
  ; Usage    : mysql_read_query_result(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_read_query_result(*mysql.MYSQL) : Global mysql_read_query_result.PB_mysql_read_query_result = GetFunction(#MySQLLib,"mysql_read_query_result")
  
  ; Function : mysql_reload()
  ; Usage    : mysql_reload(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_reload(*mysql.MYSQL) : Global mysql_reload.PB_mysql_reload = GetFunction(#MySQLLib,"mysql_reload")
  
  ; Function : mysql_rollback()
  ; Usage    : mysql_rollback(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_rollback(*mysql.MYSQL) : Global mysql_rollback.PB_mysql_rollback = GetFunction(#MySQLLib,"mysql_rollback")
  
  ; Function : mysql_rpl_parse_enabled()
  ; Usage    : mysql_rpl_parse_enabled(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_rpl_parse_enabled(*mysql.MYSQL) : Global mysql_rpl_parse_enabled.PB_mysql_rpl_parse_enabled = GetFunction(#MySQLLib,"mysql_rpl_parse_enabled")
  
  ; Function : mysql_rpl_probe()
  ; Usage    : mysql_rpl_probe(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_rpl_probe(*mysql.MYSQL) : Global mysql_rpl_probe.PB_mysql_rpl_probe = GetFunction(#MySQLLib,"mysql_rpl_probe")
  
  ; Function : mysql_server_end()
  ; Usage    : mysql_server_end() 
  ; Desc     : 
  PrototypeC.l PB_mysql_server_end() : Global mysql_server_end.PB_mysql_server_end = GetFunction(#MySQLLib,"mysql_server_end")
  
  ; Function : mysql_thread_end()
  ; Usage    : mysql_thread_end() 
  ; Desc     : 
  PrototypeC.l PB_mysql_thread_end() : Global mysql_thread_end.PB_mysql_thread_end = GetFunction(#MySQLLib,"mysql_thread_end")
  
  ; Function : mysql_thread_init()
  ; Usage    : mysql_thread_init() 
  ; Desc     : 
  PrototypeC.l PB_mysql_thread_init() : Global mysql_thread_init.PB_mysql_thread_init = GetFunction(#MySQLLib,"mysql_thread_init")
  
  ; Function : mysql_thread_safe()
  ; Usage    : mysql_thread_safe() 
  ; Desc     : 
  PrototypeC.l PB_mysql_thread_safe() : Global mysql_thread_safe.PB_mysql_thread_safe = GetFunction(#MySQLLib,"mysql_thread_safe")
  
  ; Function : mysql_stat()
  ; Usage    : mysql_stat(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_stat(*mysql.MYSQL) : Global mysql_stat.PB_mysql_stat = GetFunction(#MySQLLib,"mysql_stat")
  
  ; Function : mysql_store_result()
  ; Usage    : *MySQLResult = mysql_store_result(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_store_result(*mysql.MYSQL) : Global mysql_store_result.PB_mysql_store_result = GetFunction(#MySQLLib,"mysql_store_result")
  
  ; Function : mysql_thread_id()
  ; Usage    : Result.l = mysql_thread_id(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_thread_id(*mysql.MYSQL) : Global mysql_thread_id.PB_mysql_thread_id = GetFunction(#MySQLLib,"mysql_thread_id")
  
  ; Function : mysql_use_result()
  ; Usage    : mysql_use_result(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_use_result(*mysql.MYSQL) : Global mysql_use_result.PB_mysql_use_result = GetFunction(#MySQLLib,"mysql_use_result")
  
  ; Function : mysql_warning_count()
  ; Usage    : mysql_warning_count(*MySQLHandle) 
  ; Desc     : 
  PrototypeC.l PB_mysql_warning_count(*mysql.MYSQL) : Global mysql_warning_count.PB_mysql_warning_count = GetFunction(#MySQLLib,"mysql_warning_count")
  
  ; Function : mysql_change_user()
  ; Usage    : mysql_change_user(*MySQLHandle, user.s, passwd.s, db.s) 
  ; Desc     : 
  PrototypeC.l PB_mysql_change_user(*mysql.MYSQL,user.s,passwd.s,db.s) : Global mysql_change_user.PB_mysql_change_user = GetFunction(#MySQLLib,"mysql_change_user")
  
  ; Function : mysql_data_seek()
  ; Usage    : mysql_data_seek(*MySQLResult, offset.d) 
  ; Desc     : 
  PrototypeC.l PB_mysql_data_seek(*result.MYSQL_RES,offset.d) : Global mysql_data_seek.PB_mysql_data_seek = GetFunction(#MySQLLib,"mysql_data_seek")
  
  ; Function : mysql_eof()
  ; Usage    : mysql_eof(*MySQLResult) 
  ; Desc     : 
  PrototypeC.l PB_mysql_eof(*result.MYSQL_RES) : Global mysql_eof.PB_mysql_eof = GetFunction(#MySQLLib,"mysql_eof")
  
  ; Function : mysql_escape_string()
  ; Usage    : mysql_escape_string(strTo.s, strFrom.s, length.l) 
  ; Desc     : 
  PrototypeC.l PB_mysql_escape_string(strTo.s,strFrom.s,length.l) : Global mysql_escape_string.PB_mysql_escape_string = GetFunction(#MySQLLib,"mysql_escape_string")
  
  ; Function : mysql_fetch_field()
  ; Usage    : *field.MYSQL_FIELD = mysql_fetch_field(*MySQLResult) 
  ; Desc     : 
  PrototypeC.l PB_mysql_fetch_field(*result.MYSQL_RES) : Global mysql_fetch_field.PB_mysql_fetch_field = GetFunction(#MySQLLib,"mysql_fetch_field")
  
  ; Function : mysql_fetch_field_direct()
  ; Usage    : *field.MYSQL_FIELD = mysql_fetch_field_direct(*MySQLResult, fieldnr.l) 
  ; Desc     : 
  PrototypeC.l PB_mysql_fetch_field_direct(*result.MYSQL_RES,fieldnr.l) : Global mysql_fetch_field_direct.PB_mysql_fetch_field_direct = GetFunction(#MySQLLib,"mysql_fetch_field_direct")
  
  ; Function : mysql_fetch_fields()
  ; Usage    : *fieldArray.MYSQL_FIELD = mysql_fetch_fields(*MySQLResult) 
  ; Desc     : 
  PrototypeC.l PB_mysql_fetch_fields(*result.MYSQL_RES) : Global mysql_fetch_fields.PB_mysql_fetch_fields = GetFunction(#MySQLLib,"mysql_fetch_fields")
  
  ; Function : mysql_fetch_lengths()
  ; Usage    : mysql_fetch_lengths(*MySQLResult) 
  ; Desc     : 
  PrototypeC.l PB_mysql_fetch_lengths(*result.MYSQL_RES) : Global mysql_fetch_lengths.PB_mysql_fetch_lengths = GetFunction(#MySQLLib,"mysql_fetch_lengths")
  
  ; Function : mysql_fetch_row()
  ; Usage    : *row.MYSQL_ROW = mysql_fetch_row(*MySQLResult) 
  ; Desc     : 
  PrototypeC.l PB_mysql_fetch_row(*result.MYSQL_RES) : Global mysql_fetch_row.PB_mysql_fetch_row = GetFunction(#MySQLLib,"mysql_fetch_row")
  
  ; Function : mysql_field_seek()
  ; Usage    : mysql_field_seek(*MySQLResult, offset.l) 
  ; Desc     : 
  PrototypeC.l PB_mysql_field_seek(*result.MYSQL_RES,offset.l) : Global mysql_field_seek.PB_mysql_field_seek = GetFunction(#MySQLLib,"mysql_field_seek")
  
  ; Function : mysql_field_tell()
  ; Usage    : mysql_field_tell(*MySQLResult) 
  ; Desc     : 
  PrototypeC.l PB_mysql_field_tell(*result.MYSQL_RES) : Global mysql_field_tell.PB_mysql_field_tell = GetFunction(#MySQLLib,"mysql_field_tell")
  
  ; Function : mysql_free_result()
  ; Usage    : mysql_free_result(*MySQLResult) 
  ; Desc     : 
  PrototypeC.l PB_mysql_free_result(*result.MYSQL_RES) : Global mysql_free_result.PB_mysql_free_result = GetFunction(#MySQLLib,"mysql_free_result")
  
  ; Function : mysql_get_character_set_info()
  ; Usage    : mysql_get_character_set_info(*MySQLResult, *MySQL_CharsetInfo) 
  ; Desc     : 
  PrototypeC.l PB_mysql_get_character_set_info(*mysql.MYSQL,*cs.MY_CHARSET_INFO) : Global mysql_get_character_set_info.PB_mysql_get_character_set_info = GetFunction(#MySQLLib,"mysql_get_character_set_info")
  
  ; Function : mysql_hex_string()
  ; Usage    : mysql_hex_string(strTo.s, strFrom.s, length.l) 
  ; Desc     : 
  PrototypeC.l PB_mysql_hex_string(strTo.s,strFrom.s,length.l) : Global mysql_hex_string.PB_mysql_hex_string = GetFunction(#MySQLLib,"mysql_hex_string")
  
  ; Function : mysql_kill()
  ; Usage    : mysql_kill(*MySQLHandle, pid.l) 
  ; Desc     : 
  PrototypeC.l PB_mysql_kill(*mysql.MYSQL,pid.l) : Global mysql_kill.PB_mysql_kill = GetFunction(#MySQLLib,"mysql_kill")
  
  ; Function : mysql_library_init()
  ; Usage    : mysql_library_init(argc.l, argv.l, groups.l) 
  ; Desc     : 
  PrototypeC.l PB_mysql_library_init(argc.l,argv.l,Groups.l) : Global mysql_library_init.PB_mysql_library_init = GetFunction(#MySQLLib,"mysql_library_init")
  
  ; Function : mysql_list_dbs()
  ; Usage    : mysql_list_dbs(*MySQLHandle, Wildcard.s) 
  ; Desc     : 
  PrototypeC.l PB_mysql_list_dbs(*mysql.MYSQL,wild.s) : Global mysql_list_dbs.PB_mysql_list_dbs = GetFunction(#MySQLLib,"mysql_list_dbs")
  
  ; Function : mysql_list_fields()
  ; Usage    : mysql_list_fields(*MySQLHandle, Table.s, Wildcard.s) 
  ; Desc     : 
  PrototypeC.l PB_mysql_list_fields(*mysql.MYSQL,table.s,wild.s) : Global mysql_list_fields.PB_mysql_list_fields = GetFunction(#MySQLLib,"mysql_list_fields")
  
  ; Function : mysql_list_tables()
  ; Usage    : mysql_list_tables(*MySQLHandle, Wildcard.s) 
  ; Desc     : 
  PrototypeC.l PB_mysql_list_tables(*mysql.MYSQL,wild.s) : Global mysql_list_tables.PB_mysql_list_tables = GetFunction(#MySQLLib,"mysql_list_tables")
  
  ; Function : mysql_master_query()
  ; Usage    : mysql_master_query(*MySQLHandle, query.s, length.l) 
  ; Desc     : 
  PrototypeC.l PB_mysql_master_query(*mysql.MYSQL,query.s,length.l) : Global mysql_master_query.PB_mysql_master_query = GetFunction(#MySQLLib,"mysql_master_query")
  
  ; Function : mysql_num_fields()
  ; Usage    : Result.l = mysql_num_fields(*MySQLResult) 
  ; Desc     : 
  PrototypeC.l PB_mysql_num_fields(*result.MYSQL_RES) : Global mysql_num_fields.PB_mysql_num_fields = GetFunction(#MySQLLib,"mysql_num_fields")
  
  ; Function : mysql_num_rows()
  ; Usage    : Result.l = mysql_num_rows(*MySQLResult) 
  ; Desc     : 
  PrototypeC.l PB_mysql_num_rows(*result.MYSQL_RES) : Global mysql_num_rows.PB_mysql_num_rows = GetFunction(#MySQLLib,"mysql_num_rows")
  
  ; Function : mysql_options()
  ; Usage    : Result.l = mysql_options(*MySQLHandle, option.l, arg.s) 
  ; Desc     : 
  PrototypeC.l PB_mysql_options(*mysql.MYSQL,option.l,arg.s) : Global mysql_options.PB_mysql_options = GetFunction(#MySQLLib,"mysql_options")
  
  ; Function : mysql_query()
  ; Usage    : Result.l = mysql_query(*MySQLHandle, query.s) 
  ; Desc     : 
  PrototypeC.l PB_mysql_query(*mysql.MYSQL,query.s) : Global mysql_query.PB_mysql_query = GetFunction(#MySQLLib,"mysql_query")
  
  ; Function : mysql_real_escape_string()
  ; Usage    : mysql_real_escape_string(*MySQLHandle, strTo.s, strFrom.s, length.l) 
  ; Desc     : 
  PrototypeC.l PB_mysql_real_escape_string(*mysql.MYSQL,strTo.s,strFrom.s,length.l) : Global mysql_real_escape_string.PB_mysql_real_escape_string = GetFunction(#MySQLLib,"mysql_real_escape_string")
  
  ; Function : mysql_real_query()
  ; Usage    : *MySQLResult = mysql_real_query(*MySQLHandle, query.s, length.l) 
  ; Desc     : 
  PrototypeC.l PB_mysql_real_query(*mysql.MYSQL,query.s,length.l) : Global mysql_real_query.PB_mysql_real_query = GetFunction(#MySQLLib,"mysql_real_query")
  
  ; Function : mysql_refresh()
  ; Usage    : mysql_refresh(*MySQLHandle, options.l) 
  ; Desc     : 
  PrototypeC.l PB_mysql_refresh(*mysql.MYSQL,Options.l) : Global mysql_refresh.PB_mysql_refresh = GetFunction(#MySQLLib,"mysql_refresh")
  
  ; Function : mysql_row_seek()
  ; Usage    : mysql_row_seek(*MySQLHandle, offset.l) 
  ; Desc     : 
  PrototypeC.l PB_mysql_row_seek(*mysql.MYSQL,offset.l) : Global mysql_row_seek.PB_mysql_row_seek = GetFunction(#MySQLLib,"mysql_row_seek")
  
  ; Function : mysql_row_tell()
  ; Usage    : mysql_row_tell(*MySQLResult) 
  ; Desc     : 
  PrototypeC.l PB_mysql_row_tell(*result.MYSQL_RES) : Global mysql_row_tell.PB_mysql_row_tell = GetFunction(#MySQLLib,"mysql_row_tell")
  
  ; Function : mysql_rpl_query_type()
  ; Usage    : mysql_rpl_query_type(*MySQLHandle, type.l) 
  ; Desc     : 
  PrototypeC.l PB_mysql_rpl_query_type(*mysql.MYSQL,type.l) : Global mysql_rpl_query_type.PB_mysql_rpl_query_type = GetFunction(#MySQLLib,"mysql_rpl_query_type")
  
  ; Function : mysql_send_query()
  ; Usage    : mysql_send_query(*MySQLHandle, query.s, length.l) 
  ; Desc     : 
  PrototypeC.l PB_mysql_send_query(*mysql.MYSQL,query.s,length.l) : Global mysql_send_query.PB_mysql_send_query = GetFunction(#MySQLLib,"mysql_send_query")
  
  ; Function : mysql_server_init()
  ; Usage    : mysql_server_init(argc.l, argv.l, groups.l) 
  ; Desc     : 
  PrototypeC.l PB_mysql_server_init(argc.l,argv.l,Groups.l) : Global mysql_server_init.PB_mysql_server_init = GetFunction(#MySQLLib,"mysql_server_init")
  
  ; Function : mysql_set_character_set()
  ; Usage    : mysql_set_character_set(*MySQLHandle, csname.s) 
  ; Desc     : 
  PrototypeC.l PB_mysql_set_character_set(*mysql.MYSQL,csname.s) : Global mysql_set_character_set.PB_mysql_set_character_set = GetFunction(#MySQLLib,"mysql_set_character_set")
  
  ; Function : mysql_set_server_option()
  ; Usage    : mysql_set_server_option(*MySQLHandle, option.l) 
  ; Desc     : 
  PrototypeC.l PB_mysql_set_server_option(*mysql.MYSQL,option.l) : Global mysql_set_server_option.PB_mysql_set_server_option = GetFunction(#MySQLLib,"mysql_set_server_option")
  
  ; Function : mysql_shutdown()
  ; Usage    : mysql_shutdown(*MySQLHandle, shutdown_level.l) 
  ; Desc     : 
  PrototypeC.l PB_mysql_shutdown(*mysql.MYSQL,shutdown_level.l) : Global mysql_shutdown.PB_mysql_shutdown = GetFunction(#MySQLLib,"mysql_shutdown")
  
  ; Function : mysql_slave_query()
  ; Usage    : mysql_slave_query(*MySQLHandle, query.s, length.l) 
  ; Desc     : 
  PrototypeC.l PB_mysql_slave_query(*mysql.MYSQL,query.s,length.l) : Global mysql_slave_query.PB_mysql_slave_query = GetFunction(#MySQLLib,"mysql_slave_query")
  
  ; Function : mysql_ssl_set()
  ; Usage    : mysql_ssl_set(*MySQLHandle, key.s, cert.s, ca.s, capath.s, cipher.s) 
  ; Desc     : 
  PrototypeC.l PB_mysql_ssl_set(*mysql.MYSQL,key.s,cert.s,ca.s,capath.s,cipher.s) : Global mysql_ssl_set.PB_mysql_ssl_set = GetFunction(#MySQLLib,"mysql_ssl_set")
  
  EndIf
Else
  MessageRequester("MySQL Wrapper","Unable to open MySQL Library")
EndIf
EndMacro

; Free's MySQL Library for a clean exit
Macro FreeMySQL()
  If IsLibrary(#MySQLLib)
    CloseLibrary(#MySQLLib) 
  EndIf
EndMacro

  ; Test / Example ( uncomment meh! ;) ) *************************************************************


;   InitMySQL() ; <- We Initialize the dll at Start 
;   
;   OpenConsole()
; 
;   Debug "Info:    " + PeekS(mysql_get_client_info())
;   Debug "Version: " + Str(mysql_get_client_version())
;   Debug Hex(mysql_get_parameters()) 
;   
;   *hDB = mysql_init(#Null)
; 
;   If *hDB      
;     If mysql_real_connect(*hDB,"127.0.0.1","root","password","",3306,"NULL",#Null)
;       mysql_autocommit(*hDB,#True)
;       Debug "Connected!" 
;       Debug mysql_get_server_version(*hDB)
; 
;       
;       Debug "Server:"
;       Debug PeekS(mysql_get_server_info(*hDB))
;       Debug "Connection:" 
;       Debug PeekS(mysql_get_host_info(*hDB)) 
;       Debug "Protocolgeneration:"
;       Debug Str(mysql_get_proto_info(*hDB)) 
;       
;       If mysql_select_db(*hDB,"test") <> 1
;         Debug "* DB Selected"
;         
;         If mysql_query(*hDB,"SHOW TABLES") <> 1
;           Debug "* Query made..."
;           ; get next INSERT ID 
;           id = mysql_insert_id(*hDB)
;           If id
;             Debug "id>"+Str(id)
;           EndIf
;           ; get query info
;           *info = mysql_info(*hDB)
;           If *info
;             Debug PeekS(*info)
;           EndIf
;           
;           ; do we have a Result ?
;           If mysql_field_count(*hDB)
;             *result = mysql_store_result(*hDB)
;             
;             If *result
;               Debug "* Got Result!"
;               nRows.l = mysql_num_rows(*result)
;               Debug "Num Rows: " + Str(nRows.l)
;               
;               For i = 0 To nRows.l - 1
;                 *row.MYSQL_ROW = mysql_fetch_row(*result)
;                 If *row
;                     Rows.s = ""
;                     For j = 0 To mysql_num_fields(*result) - 1
;                         Rows + *row\field[j] + ", "
;                     Next
;                   PrintN(Rows)
;                   Debug "rows>"+Rows
;                 EndIf
;               Next
;               
;               mysql_free_result(*result)
;             EndIf
;             
;           EndIf
;           
;         Else
;           Debug PeekS(mysql_error(*hDB)) 
;         EndIf
;         
;       Else
;         Debug Str(mysql_errno(*hDB)) 
;         Debug "Database Error!"
;         Debug PeekS(mysql_error(*hDB)) 
;       EndIf
;     
;     Else ; No Connect, Error! 
;       Debug "Error: " 
;       Debug PeekS(mysql_error(*hDB)) 
;     EndIf
;     
;     mysql_close(*hDB)
;     
;   EndIf
;   
;   FreeMySQL() ; <- for a clean exit we free Ressources.
  ; *************************************************************************************************

Cheers,
Thalius

thanks

Posted: Sat Feb 02, 2008 11:38 pm
by quasiperfect
thanks
u'r a live saver, i realy needed something crossplatform
any updates to the code ?

Error: Can't connect to MySQL server

Posted: Sun Feb 03, 2008 11:21 am
by akj
I cannot get Thalius's code to work. I always get the Debug output:

Executable started.
[Debug] Info: 5.0.27
[Debug] Version: 50027
[Debug] 1C59E7C
[Debug] Error:
[Debug] Can't connect to MySQL server on '127.0.0.1' (10061)
Execution stopped. (Program about to end)

On my Windows ME system, I have downloaded libmysql.dll from www.dll-files.com into C:\Windows\System and the file C:\Windows\HOSTS contains the line:
127.0.0.1 localhost

How can I get MySQL working?

Posted: Sun Feb 03, 2008 5:46 pm
by Thalius
is the MySQL Server on localhost running?.

Otherwise i dont see why it wouldnt work as the dll version is recognized correctly.

Ill give it a whirl to implement the rest of Features one of theese days.

Thanks for teh Feedback :)

Thalius

Posted: Sun Feb 03, 2008 7:14 pm
by akj
@Thalius
You say "Is the MySQL Server on localhost running?"
No it's not.

I was afraid that was the problem. I was hoping that the presence of libmysql.dll would be sufficient as is the case with SQLite, but I'm obviously wrong.

Thanks for your comments.

Posted: Sat May 03, 2008 9:10 am
by y3an
thanks
u'r a live saver, i realy needed something crossplatform
+1 :D

This might help!

Posted: Thu May 08, 2008 2:33 am
by Harry0
akj,

If you haven't already solved this, the following mught be of some help.

in the line

Code: Select all

If mysql_real_connect(*hDB,"127.0.0.1","root","password","",3306,"NULL",#Null)
The second parameter is the IP address of the MySQL server you are trying to connect to.

You should be able to change that to the IP of your MySQL server.

Also the third and fourth parameters (userID and Password) need to match.

Hope this helps.

Harry0

mySQL under windows

Posted: Fri Jul 04, 2008 6:08 pm
by Motu
Hi Thalius,
there is something wrong in your code. Under Windows you need to use Prototype instead of PrototypeC. I solved the problem by defining macros inside the os compiler if

Code: Select all

CompilerSelect #PB_Compiler_OS 
  CompilerCase #PB_OS_Windows 
    MysqlDllFilename$ = "libmysql.dll" 
    Macro myprotottyp()
     Prototype
    EndMacro
  CompilerCase #PB_OS_Linux 
    MysqlDllFilename$ = "libmysqlclient.so" 
    Macro myprotottyp()
     PrototypeC
    EndMacro
  CompilerCase #PB_OS_MacOS 
    MysqlDllFilename$ = "libmysqlclient.so" 
    Macro myprotottyp()
     PrototypeC
    EndMacro
  CompilerCase #PB_OS_AmigaOS 
    MysqlDllFilename$ = "mysqlclient.library" 
    Macro myprotottyp()
     PrototypeC
    EndMacro
CompilerEndSelect 
Anyway, nice pice of code :)

Motu

Posted: Thu Jul 17, 2008 12:24 am
by Straker
Has anyone gotten this to work on Windows? I keep getting memory access errors when running the test code. I even updated using Motu's changes.

I have a valid installation of MySql, and its finding and loading the DLL with no problem.

Please help. I am using PB 4.20

Thanks.

EDIT: I have narrowed it down to the following lines:

Code: Select all

548: Debug "Version: " + Str(mysql_get_client_version())
549: Debug Hex(mysql_get_parameters())

555: mysql_autocommit(*hDB,#True)

557: Debug mysql_get_server_version(*hDB)


Posted: Mon Sep 22, 2008 3:44 pm
by Thalius
Working here - tho ill look over it theese days (if all goes well also with transaction functions) - as i need that thing again for a work project. Ill post the updated version as soon as i got it done.

Thalius

Posted: Thu Oct 02, 2008 6:10 am
by lexvictory
Just what I was looking for! thanks :)

Modified to be unicode safe and use import instead of prototypes (my personal preference)
windows needs libmysql.lib (installed with mysql in the lib folder, or here)

header not edited.

Code: Select all

; MySQL 5 DLL-Wrapper Include - Version: 0.2b
; OS: Linux / Windows / AmigaOS / MacOSX ? ( can somone test this ? )
; Author: Marius Eckardt (Thalius)
; Syntaxcompatible & based on LibMySQL by Flype
; Last Changes: 29.10.2007
;
; Inspired by Flype's Userlib for Windows - i just needed a Version that runs under Linux aswell.
; There could have been alot of more checks/wraps, but in favor of speed and compatibility with Flype's
; Userlib i kept the Syntax the same.
;
; Requirements ( Version 5x of ):
; Linux  : libmysqlclient.so  - ( installed with "mysql-shared" Pakages )
; MacOSX : libmysqlclient.so
; Windows: libmysql.dll
; AmigaOS: mysqlclient.library
;
; ToDo:
;  - Bugfixes ! ( getting used to Prototype's ... ;)
;  - Descriptions / Examples
;  - stmt functions
; -----------------------------------------------------------------------------------------------

;- OS Check
CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Windows
    #MysqlDllFilename$ = "libmysql.lib"
  CompilerCase #PB_OS_Linux
    #MysqlDllFilename$ = "/usr/lib/libmysqlclient.so";symlink may be needed
  CompilerCase #PB_OS_MacOS
    #MysqlDllFilename$ = "libmysqlclient.so"
  CompilerCase #PB_OS_AmigaOS
    #MysqlDllFilename$ = "mysqlclient.library"
CompilerEndSelect

;- Structures
Structure MYSQL
EndStructure
Structure MYSQL_RES
EndStructure
Structure MYSQL_BIND
EndStructure
Structure MYSQL_STMT
EndStructure

Structure MYSQL_ROW
  *field[255]
EndStructure
Structure MYSQL_FIELD
  name.s
  org_name.s
  table.s
  org_table.s
  db.s
  catalog.s
  def.s
  length.l
  max_length.l
  name_length.l
  org_name_length.l
  table_length.l
  org_table_length.l
  db_length.l
  catalog_length.l
  def_length.l
  flags.l
  decimals.l
  charset_nr.l
  type.l
EndStructure
Structure MY_CHARSET_INFO
  number.l
  state.l
  csname.s
  name.s
  Comment.s
  dir.s
  mbminlen.l
  mbmaxlen.l
EndStructure

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Import #MysqlDllFilename$
CompilerElse
  ImportC #MysqlDllFilename$
CompilerEndIf

 
  ; ** Start Prototypes **
 
  ; Function : mysql_get_client_info()
  ; Usage    : PeekS(mysql_get_client_info())
  ; Desc     : Returns Pointer to Version STRING of Mysql Client
  mysql_get_client_info()
 
  ; Function : mysql_get_client_version()
  ; Usage    : Result.l = mysql_get_client_version()
  ; Desc     : Returns Versionnumber as LONG of Mysql Client
  mysql_get_client_version()
 
  ; Function : mysql_errno()
  ; Usage    : Result.l = mysql_get_client_info(*MySQLHandle)
  ; Desc     : Returns Error No as LONG
  mysql_errno(*mysql.MYSQL)
 
  ; Function : mysql_init()
  ; Usage    : *MySQLHandle = mysql_init(#Null)
  ; Desc     : Returns MySQL DB Handle as LONG
  mysql_init(*mysql.MYSQL) 
 
  ; Function : mysql_real_connect(*mysql.MYSQL,host.p-utf8,user.p-utf8,passwd.p-utf8,db.p-utf8,port.l,unix_socket.p-utf8,client_flag.l)
  ; Usage    : Result.l = mysql_real_connect(*mysql.MYSQL,host.p-utf8,user.p-utf8,passwd.p-utf8,db.p-utf8,port.l,unix_socket.p-utf8,client_flag.l)
  ; Desc     :
  mysql_real_connect(*mysql.MYSQL,host.p-utf8,user.p-utf8,passwd.p-utf8,db.p-utf8,port.l,unix_socket.p-utf8,client_flag.l) 
 
  ; Function : mysql_get_parameters()
  ; Usage    : debug Hex(mysql_get_parameters())
  ; Desc     :
  mysql_get_parameters()
 
  ; Function : mysql_sqlstate()
  ; Usage    : State.p-utf8 = PeekS(mysql_sqlstate(*MySQLHandle))
  ; Desc     :
  mysql_sqlstate(*mysql.MYSQL)
 
  ; Function : mysql_error()
  ; Usage    : PeekS(mysql_error(*MySQLHandle))
  ; Desc     : Returns Pointer as LONG to ErrormessageString
  mysql_error(*mysql.MYSQL)
 
  ; Function : mysql_get_server_version()
  ; Usage    : Result.l = mysql_get_server_version(*MySQLHandle)
  ; Desc     : Returns LONG from ServerVersion
  mysql_get_server_version(*mysql.MYSQL)
 
  ; Function : mysql_get_server_info()
  ; Usage    : PeekS(mysql_get_server_info(*MySQLHandle))
  ; Desc     : Returns Pointer as LONG to ServerInfoString
  mysql_get_server_info(*mysql.MYSQL)
 
  ; Function : mysql_get_host_info()
  ; Usage    : PeekS(mysql_get_host_info(*MySQLHandle))
  ; Desc     : Returns Pointer as LONG to HostInfoString / Connectioninfo
  mysql_get_host_info(*mysql.MYSQL) 
 
  ; Function : mysql_select_db()
  ; Usage    : mysql_select_db(*MySQLHandle, Databasename.p-utf8)
  ; Desc     : Selects current Database
  mysql_select_db(*mysql.MYSQL, Databasename.p-utf8)
 
  ; Function : mysql_get_proto_info()
  ; Usage    : Result.l = mysql_get_proto_info(*MySQLHandle))
  ; Desc     :
  mysql_get_proto_info(*mysql.MYSQL)
 
  ; Function : mysql_info()
  ; Usage    : Result.l = mysql_info(*MySQLHandle))
  ; Desc     :
  mysql_info(*mysql.MYSQL)
 
  ; Function : mysql_insert_id()
  ; Usage    : Result.l = mysql_insert_id(*MySQLHandle))
  ; Desc     : Returns Inserted ID as LONG
  mysql_insert_id(*mysql.MYSQL)
 
  ; Function : mysql_affected_rows()
  ; Usage    : Result.l = mysql_affected_rows(*MySQLHandle))
  ; Desc     :
  mysql_affected_rows(*mysql.MYSQL) 
 
  ; Function : mysql_autocommit()
  ; Usage    : mysql_autocommit(*MySQLHandle,#Bool) ; #True / #False
  ; Desc     :
  mysql_autocommit(*mysql.MYSQL,*mode.Byte) 
 
  ; Function : mysql_character_set_name()
  ; Usage    : mysql_character_set_name(*MySQLHandle)
  ; Desc     :
  mysql_character_set_name(*mysql.MYSQL) 
 
  ; Function : mysql_close()
  ; Usage    : mysql_close(*MySQLHandle)
  ; Desc     : Closes the MySQL Connection
  mysql_close(*mysql.MYSQL) 
 
  ; Function : mysql_commit()
  ; Usage    : mysql_commit(*MySQLHandle)
  ; Desc     :
  mysql_commit(*mysql.MYSQL) 
 
  ; Function : mysql_debug()
  ; Usage    : mysql_debug(DebugString.p-utf8)
  ; Desc     :
  mysql_debug(DebugString.p-utf8) 
 
  ; Function : mysql_disable_reads_from_master()
  ; Usage    : mysql_disable_reads_from_master(*MySQLHandle)
  ; Desc     :
  mysql_disable_reads_from_master(*mysql.MYSQL) 
 
  ; Function : mysql_disable_rpl_parse()
  ; Usage    : mysql_disable_rpl_parse(*MySQLHandle)
  ; Desc     :
  mysql_disable_rpl_parse(*mysql.MYSQL) 
 
  ; Function : mysql_dumPB_debug_info()
  ; Usage    : mysql_dumPB_debug_info(*MySQLHandle)
  ; Desc     :
  mysql_dumPB_debug_info(*mysql.MYSQL) 
 
  ; Function : mysql_embedded()
  ; Usage    : mysql_embedded()
  ; Desc     :
  mysql_embedded() 
 
  ; Function : mysql_enable_reads_from_master()
  ; Usage    : mysql_enable_reads_from_master(*MySQLHandle)
  ; Desc     :
  mysql_enable_reads_from_master(*mysql.MYSQL) 
 
  ; Function : mysql_enable_rpl_parse()
  ; Usage    : mysql_enable_rpl_parse(*MySQLHandle)
  ; Desc     :
  mysql_enable_rpl_parse(*mysql.MYSQL) 
 
  ; Function : mysql_field_count()
  ; Usage    : mysql_field_count(*MySQLHandle)
  ; Desc     :
  mysql_field_count(*mysql.MYSQL) 
 
  ; Function : mysql_library_end()
  ; Usage    : mysql_library_end(*MySQLHandle)
  ; Desc     :
  mysql_library_end(*mysql.MYSQL) 
 
  ; Function : mysql_list_processes()
  ; Usage    : mysql_list_processes(*MySQLHandle)
  ; Desc     :
  mysql_list_processes(*mysql.MYSQL) 
 
  ; Function : mysql_more_results()
  ; Usage    : mysql_more_results(*MySQLHandle)
  ; Desc     :
  mysql_more_results(*mysql.MYSQL) 
 
  ; Function : mysql_next_result()
  ; Usage    : mysql_next_result(*MySQLHandle)
  ; Desc     :
  mysql_next_result(*mysql.MYSQL) 
 
  ; Function : mysql_ping()
  ; Usage    : mysql_ping(*MySQLHandle)
  ; Desc     :
  mysql_ping(*mysql.MYSQL) 
 
  ; Function : mysql_read_query_result()
  ; Usage    : mysql_read_query_result(*MySQLHandle)
  ; Desc     :
  mysql_read_query_result(*mysql.MYSQL) 
 
  ; Function : mysql_reload()
  ; Usage    : mysql_reload(*MySQLHandle)
  ; Desc     :
  mysql_reload(*mysql.MYSQL) 
 
  ; Function : mysql_rollback()
  ; Usage    : mysql_rollback(*MySQLHandle)
  ; Desc     :
  mysql_rollback(*mysql.MYSQL) 
 
  ; Function : mysql_rpl_parse_enabled()
  ; Usage    : mysql_rpl_parse_enabled(*MySQLHandle)
  ; Desc     :
  mysql_rpl_parse_enabled(*mysql.MYSQL) 
 
  ; Function : mysql_rpl_probe()
  ; Usage    : mysql_rpl_probe(*MySQLHandle)
  ; Desc     :
  mysql_rpl_probe(*mysql.MYSQL) 
 
  ; Function : mysql_server_end()
  ; Usage    : mysql_server_end()
  ; Desc     :
  mysql_server_end() 
 
  ; Function : mysql_thread_end()
  ; Usage    : mysql_thread_end()
  ; Desc     :
  mysql_thread_end() 
 
  ; Function : mysql_thread_init()
  ; Usage    : mysql_thread_init()
  ; Desc     :
  mysql_thread_init() 
 
  ; Function : mysql_thread_safe()
  ; Usage    : mysql_thread_safe()
  ; Desc     :
  mysql_thread_safe() 
 
  ; Function : mysql_stat()
  ; Usage    : mysql_stat(*MySQLHandle)
  ; Desc     :
  mysql_stat(*mysql.MYSQL) 
 
  ; Function : mysql_store_result()
  ; Usage    : *MySQLResult = mysql_store_result(*MySQLHandle)
  ; Desc     :
  mysql_store_result(*mysql.MYSQL)
 
  ; Function : mysql_thread_id()
  ; Usage    : Result.l = mysql_thread_id(*MySQLHandle)
  ; Desc     :
  mysql_thread_id(*mysql.MYSQL) 
 
  ; Function : mysql_use_result()
  ; Usage    : mysql_use_result(*MySQLHandle)
  ; Desc     :
  mysql_use_result(*mysql.MYSQL) 
 
  ; Function : mysql_warning_count()
  ; Usage    : mysql_warning_count(*MySQLHandle)
  ; Desc     :
  mysql_warning_count(*mysql.MYSQL) 
 
  ; Function : mysql_change_user()
  ; Usage    : mysql_change_user(*MySQLHandle, user.p-utf8, passwd.p-utf8, db.p-utf8)
  ; Desc     :
  mysql_change_user(*mysql.MYSQL,user.p-utf8,passwd.p-utf8,db.p-utf8) 
 
  ; Function : mysql_data_seek()
  ; Usage    : mysql_data_seek(*MySQLResult, offset.d)
  ; Desc     :
  mysql_data_seek(*result.MYSQL_RES,offset.d) 
 
  ; Function : mysql_eof()
  ; Usage    : mysql_eof(*MySQLResult)
  ; Desc     :
  mysql_eof(*result.MYSQL_RES) 
 
  ; Function : mysql_escape_string()
  ; Usage    : mysql_escape_string(strTo.p-utf8, strFrom.p-utf8, length.l)
  ; Desc     :
  mysql_escape_string(strTo.p-utf8,strFrom.p-utf8,length.l) 
 
  ; Function : mysql_fetch_field()
  ; Usage    : *field.MYSQL_FIELD = mysql_fetch_field(*MySQLResult)
  ; Desc     :
  mysql_fetch_field(*result.MYSQL_RES) 
 
  ; Function : mysql_fetch_field_direct()
  ; Usage    : *field.MYSQL_FIELD = mysql_fetch_field_direct(*MySQLResult, fieldnr.l)
  ; Desc     :
  mysql_fetch_field_direct(*result.MYSQL_RES,fieldnr.l) 
 
  ; Function : mysql_fetch_fields()
  ; Usage    : *fieldArray.MYSQL_FIELD = mysql_fetch_fields(*MySQLResult)
  ; Desc     :
  mysql_fetch_fields(*result.MYSQL_RES) 
 
  ; Function : mysql_fetch_lengths()
  ; Usage    : mysql_fetch_lengths(*MySQLResult)
  ; Desc     :
  mysql_fetch_lengths(*result.MYSQL_RES) 
 
  ; Function : mysql_fetch_row()
  ; Usage    : *row.MYSQL_ROW = mysql_fetch_row(*MySQLResult)
  ; Desc     :
  mysql_fetch_row(*result.MYSQL_RES) 
 
  ; Function : mysql_field_seek()
  ; Usage    : mysql_field_seek(*MySQLResult, offset.l)
  ; Desc     :
  mysql_field_seek(*result.MYSQL_RES,offset.l) 
 
  ; Function : mysql_field_tell()
  ; Usage    : mysql_field_tell(*MySQLResult)
  ; Desc     :
  mysql_field_tell(*result.MYSQL_RES) 
 
  ; Function : mysql_free_result()
  ; Usage    : mysql_free_result(*MySQLResult)
  ; Desc     :
  mysql_free_result(*result.MYSQL_RES) 
 
  ; Function : mysql_get_character_set_info()
  ; Usage    : mysql_get_character_set_info(*MySQLResult, *MySQL_CharsetInfo)
  ; Desc     :
  mysql_get_character_set_info(*mysql.MYSQL,*cs.MY_CHARSET_INFO) 
 
  ; Function : mysql_hex_string()
  ; Usage    : mysql_hex_string(strTo.p-utf8, strFrom.p-utf8, length.l)
  ; Desc     :
  mysql_hex_string(strTo.p-utf8,strFrom.p-utf8,length.l) 
 
  ; Function : mysql_kill()
  ; Usage    : mysql_kill(*MySQLHandle, pid.l)
  ; Desc     :
  mysql_kill(*mysql.MYSQL,pid.l) 
 
  ; Function : mysql_library_init()
  ; Usage    : mysql_library_init(argc.l, argv.l, groups.l)
  ; Desc     :
  mysql_library_init(argc.l,argv.l,Groups.l) 
 
  ; Function : mysql_list_dbs()
  ; Usage    : mysql_list_dbs(*MySQLHandle, Wildcard.p-utf8)
  ; Desc     :
  mysql_list_dbs(*mysql.MYSQL,wild.p-utf8) 
 
  ; Function : mysql_list_fields()
  ; Usage    : mysql_list_fields(*MySQLHandle, Table.p-utf8, Wildcard.p-utf8)
  ; Desc     :
  mysql_list_fields(*mysql.MYSQL,table.p-utf8,wild.p-utf8) 
 
  ; Function : mysql_list_tables()
  ; Usage    : mysql_list_tables(*MySQLHandle, Wildcard.p-utf8)
  ; Desc     :
  mysql_list_tables(*mysql.MYSQL,wild.p-utf8) 
 
  ; Function : mysql_master_query()
  ; Usage    : mysql_master_query(*MySQLHandle, query.p-utf8, length.l)
  ; Desc     :
  mysql_master_query(*mysql.MYSQL,query.p-utf8,length.l) 
 
  ; Function : mysql_num_fields()
  ; Usage    : Result.l = mysql_num_fields(*MySQLResult)
  ; Desc     :
  mysql_num_fields(*result.MYSQL_RES) 
 
  ; Function : mysql_num_rows()
  ; Usage    : Result.l = mysql_num_rows(*MySQLResult)
  ; Desc     :
  mysql_num_rows(*result.MYSQL_RES) 
 
  ; Function : mysql_options()
  ; Usage    : Result.l = mysql_options(*MySQLHandle, option.l, arg.p-utf8)
  ; Desc     :
  mysql_options(*mysql.MYSQL,option.l,arg.p-utf8) 
 
  ; Function : mysql_query()
  ; Usage    : Result.l = mysql_query(*MySQLHandle, query.p-utf8)
  ; Desc     :
  mysql_query(*mysql.MYSQL,query.p-utf8) 
 
  ; Function : mysql_real_escape_string()
  ; Usage    : mysql_real_escape_string(*MySQLHandle, strTo.p-utf8, strFrom.p-utf8, length.l)
  ; Desc     :
  mysql_real_escape_string(*mysql.MYSQL,strTo.p-utf8,strFrom.p-utf8,length.l) 
 
  ; Function : mysql_real_query()
  ; Usage    : *MySQLResult = mysql_real_query(*MySQLHandle, query.p-utf8, length.l)
  ; Desc     :
  mysql_real_query(*mysql.MYSQL,query.p-utf8,length.l) 
 
  ; Function : mysql_refresh()
  ; Usage    : mysql_refresh(*MySQLHandle, options.l)
  ; Desc     :
  mysql_refresh(*mysql.MYSQL,Options.l) 
 
  ; Function : mysql_row_seek()
  ; Usage    : mysql_row_seek(*MySQLHandle, offset.l)
  ; Desc     :
  mysql_row_seek(*mysql.MYSQL,offset.l) 
 
  ; Function : mysql_row_tell()
  ; Usage    : mysql_row_tell(*MySQLResult)
  ; Desc     :
  mysql_row_tell(*result.MYSQL_RES) 
 
  ; Function : mysql_rpl_query_type()
  ; Usage    : mysql_rpl_query_type(*MySQLHandle, type.l)
  ; Desc     :
  mysql_rpl_query_type(*mysql.MYSQL,type.l) 
 
  ; Function : mysql_send_query()
  ; Usage    : mysql_send_query(*MySQLHandle, query.p-utf8, length.l)
  ; Desc     :
  mysql_send_query(*mysql.MYSQL,query.p-utf8,length.l) 
 
  ; Function : mysql_server_init()
  ; Usage    : mysql_server_init(argc.l, argv.l, groups.l)
  ; Desc     :
  mysql_server_init(argc.l,argv.l,Groups.l) 
 
  ; Function : mysql_set_character_set()
  ; Usage    : mysql_set_character_set(*MySQLHandle, csname.p-utf8)
  ; Desc     :
  mysql_set_character_set(*mysql.MYSQL,csname.p-utf8) 
 
  ; Function : mysql_set_server_option()
  ; Usage    : mysql_set_server_option(*MySQLHandle, option.l)
  ; Desc     :
  mysql_set_server_option(*mysql.MYSQL,option.l) 
 
  ; Function : mysql_shutdown()
  ; Usage    : mysql_shutdown(*MySQLHandle, shutdown_level.l)
  ; Desc     :
  mysql_shutdown(*mysql.MYSQL,shutdown_level.l) 
 
  ; Function : mysql_slave_query()
  ; Usage    : mysql_slave_query(*MySQLHandle, query.p-utf8, length.l)
  ; Desc     :
  mysql_slave_query(*mysql.MYSQL,query.p-utf8,length.l) 
 
  ; Function : mysql_ssl_set()
  ; Usage    : mysql_ssl_set(*MySQLHandle, key.p-utf8, cert.p-utf8, ca.p-utf8, capath.p-utf8, cipher.p-utf8)
  ; Desc     :
  mysql_ssl_set(*mysql.MYSQL,key.p-utf8,cert.p-utf8,ca.p-utf8,capath.p-utf8,cipher.p-utf8) 
 
  EndImport
  
Procedure.s PeekS_Utf8(*buffer);also checks if buffer is valid, returns an empty string if *buffer is 0
  If *buffer
    ProcedureReturn PeekS(*buffer, -1, #PB_UTF8)
  Else
    ProcedureReturn ""
  EndIf
EndProcedure


;   Debug "Info:    " + PeekS(mysql_get_client_info(), -1, #PB_UTF8)
;   Debug "Version: " + Str(mysql_get_client_version())
;   Debug Hex(mysql_get_parameters())
;   
;   *hDB = mysql_init(#Null)
; 
;   If *hDB     
;     If mysql_real_connect(*hDB,"127.0.0.1","root","password","",3306,"NULL",#Null)
;       mysql_autocommit(*hDB,#True)
;       Debug "Connected!"
;       Debug mysql_get_server_version(*hDB)
; 
;       
;       Debug "Server:"
;       Debug PeekS(mysql_get_server_info(*hDB), -1, #PB_UTF8)
;       Debug "Connection:"
;       Debug PeekS(mysql_get_host_info(*hDB), -1, #PB_UTF8)
;       Debug "Protocolgeneration:"
;       Debug Str(mysql_get_proto_info(*hDB))
;       
;       If mysql_select_db(*hDB,"test") <> 1
;         Debug "* DB Selected"
;         
;         If mysql_query(*hDB,"SHOW TABLES") <> 1
;           Debug "* Query made..."
;           ; get next INSERT ID
;           id = mysql_insert_id(*hDB)
;           If id
;             Debug "id>"+Str(id)
;           EndIf
;           ; get query info
;           *info = mysql_info(*hDB)
;           If *info
;             Debug PeekS(*info, -1, #PB_UTF8)
;           EndIf
;           
;           ; do we have a Result ?
;           If mysql_field_count(*hDB)
;             *result = mysql_store_result(*hDB)
;             
;             If *result
;               Debug "* Got Result!"
;               nRows.l = mysql_num_rows(*result)
;               Debug "Num Rows: " + Str(nRows.l)
;               
;               For i = 0 To nRows.l - 1
;                 *row.MYSQL_ROW = mysql_fetch_row(*result)
;                 If *row
;                     Rows.s = ""
;                     For j = 0 To mysql_num_fields(*result) - 1
;                         Rows + PeekS_Utf8(*row\field[j]) + ", ";PeekS_Utf8() does a peeks in utf8 mode, but if *row\field[j] is null (field is empty) it returns an empty string.
;                     Next
;                   Debug Rows
;                   Debug "rows>"+Rows
;                 EndIf
;               Next
;               
;               mysql_free_result(*result)
;             EndIf
;             
;           EndIf
;           
;         Else
;           Debug PeekS(mysql_error(*hDB), -1, #PB_UTF8)
;         EndIf
;         
;       Else
;         Debug Str(mysql_errno(*hDB))
;         Debug "Database Error!"
;         Debug PeekS(mysql_error(*hDB), -1, #PB_UTF8)
;       EndIf
;     
;     Else ; No Connect, Error!
;       Debug "Error: "
;       Debug PeekS(mysql_error(*hDB), -1, #PB_UTF8)
;     EndIf
;     
;     mysql_close(*hDB)
;     
;   EndIf

  ;*************************************************************************************************
all strings need to be sent and read in utf-8 (.p-utf8 and peeks(*pointer, -1, #pb_utf8))

tested on window and linux.

Posted: Thu Jul 23, 2009 11:48 am
by Fred
I was looking to integrate native mysql support to PB via a database plugin, and while browsing the libmysql sources, i saw it was licensed as GPL. After a few search on google, even PHP5 removed native support of mysql because of license constraint.

What does it means ? It means than if you use this lib (dll or statically linked) in a non-GPL program you have a to buy a license to mysql. That's quite disappointing for such a 'free' database manager. Just wanted to let you know to avoid bad surprises.

Posted: Thu Jul 23, 2009 12:22 pm
by DoubleDutch
I think the same thing happened with Rails. They removed default support for MySQL.

Posted: Thu Jul 23, 2009 1:49 pm
by Fangbeast
Fred wrote:I was looking to integrate native mysql support to PB via a database plugin, and while browsing the libmysql sources, i saw it was licensed as GPL. After a few search on google, even PHP5 removed native support of mysql because of license constraint.

What does it means ? It means than if you use this lib (dll or statically linked) in a non-GPL program you have a to buy a license to mysql. That's quite disappointing for such a 'free' database manager. Just wanted to let you know to avoid bad surprises.
Fred, what about FireBird? It seems to be free of those licenses and a lot of people like it as it seems to be as good as SQLite but also have server technology?

Posted: Thu Jul 23, 2009 2:23 pm
by Coolman
+1, Firebird is an excellent choice 8)