MYSQL avec unicode = problème

Programmation d'applications complexes
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

MYSQL avec unicode = problème

Message par flaith »

Bonsoir les gens,

j'ai une appli à faire qui doit obligatoirement tourner en unicode, j'ai pris l'option MySQL pour la gestion de la bdb et j'utilise le wrapper suivant (fait par flype, merci à lui) ainsi que son exemple :

Code : Tout sélectionner

;- 
;- File:     libmysql.pbi
;- Version:  2.0
;- Author:   flype - flype44(at)gmail.com
;- Modified: flaith (24.07.2009)
;-
;- About:    MySQL Interface for Purebasic 4.3.
;- 
;- updated:  p-utf8 format (for unicode or ascii)

EnableExplicit

;-
;- Private - MySQL API
;-

#MYSQL_NOERROR = 0

Enumeration 0 ; client
  #CLIENT_COMPRESS
  #CLIENT_FOUND_ROWS
  #CLIENT_IGNORE_SPACE
  #CLIENT_INTERACTIVE
  #CLIENT_LOCAL_FILES
  #CLIENT_MULTI_STATEMENTS
  #CLIENT_MULTI_RESULTS
  #CLIENT_NO_SCHEMA
  #CLIENT_ODBC
  #CLIENT_SSL
EndEnumeration
Enumeration 0 ; type
  #MYSQL_TYPE_DECIMAL
  #MYSQL_TYPE_TINY
  #MYSQL_TYPE_SHORT
  #MYSQL_TYPE_LONG
  #MYSQL_TYPE_FLOAT
  #MYSQL_TYPE_DOUBLE
  #MYSQL_TYPE_NULL
  #MYSQL_TYPE_TIMESTAMP
  #MYSQL_TYPE_LONGLONG
  #MYSQL_TYPE_INT24
  #MYSQL_TYPE_DATE
  #MYSQL_TYPE_TIME
  #MYSQL_TYPE_DATETIME
  #MYSQL_TYPE_YEAR
  #MYSQL_TYPE_NEWDATE
  #MYSQL_TYPE_VARCHAR
  #MYSQL_TYPE_BIT
  #MYSQL_TYPE_NEWDECIMAL = 246
  #MYSQL_TYPE_ENUM
  #MYSQL_TYPE_SET
  #MYSQL_TYPE_TINY_BLOB
  #MYSQL_TYPE_MEDIUM_BLOB
  #MYSQL_TYPE_LONG_BLOB
  #MYSQL_TYPE_BLOB
  #MYSQL_TYPE_VAR_STRING
  #MYSQL_TYPE_STRING
  #MYSQL_TYPE_GEOMETRY
EndEnumeration

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 MYSQL_FIELD_ARRAY
  field.MYSQL_FIELD[0]
EndStructure

Structure MYSQL_LENGTH
  *l.l[0]
EndStructure
Structure MYSQL_ROW
  *field.s[0]
EndStructure

Import "libmysql.lib" 
  mysql_affected_rows(*mysql) 
  mysql_autocommit(*mysql, *mode.Byte)
  mysql_change_user(*mysql, user.p-utf8, passwd.p-utf8, db.p-utf8) 
  mysql_character_set_name(*mysql)
  mysql_close(*mysql)
  mysql_commit(*mysql)
  mysql_data_seek(*result, offset.d)
  mysql_eof(*result)
  mysql_errno(*mysql)
  mysql_error(*mysql)
  mysql_escape_string(*strTo, strFrom.p-utf8, length.l)
  mysql_fetch_field(*result)
  mysql_fetch_field_direct(*result, fieldnr.l)
  mysql_fetch_fields(*result)
  mysql_fetch_lengths(*result)
  mysql_fetch_row(*result)
  mysql_field_count(*mysql)
  mysql_field_seek(*result, offset.l)
  mysql_field_tell(*result)
  mysql_free_result(*result)
  mysql_get_character_set_info(*mysql, *charsetinfo)
  mysql_get_client_info()
  mysql_get_client_version()
  mysql_get_host_info(*mysql)
  mysql_get_parameters()
  mysql_get_proto_info(*mysql)
  mysql_get_server_info(*mysql)
  mysql_get_server_version(*mysql)
  mysql_hex_string(strTo.p-utf8, strFrom.p-utf8, length.l)
  mysql_info(*mysql)
  mysql_init(*mysql)
  mysql_insert_id(*mysql)
  mysql_kill(*mysql, pid.l)
  mysql_list_dbs(*mysql, wild.p-utf8)
  mysql_list_fields(*mysql, table.p-utf8, wild.p-utf8)
  mysql_list_processes(*mysql)
  mysql_list_tables(*mysql, wild.p-utf8)
  mysql_master_query(*mysql, query.p-utf8, length.l)
  mysql_more_results(*mysql)
  mysql_next_result(*mysql)
  mysql_num_fields(*result)
  mysql_num_rows(*result)
  mysql_options(*mysql, option.l, arg.p-utf8)
  mysql_ping(*mysql)
  mysql_query(*mysql, query.p-utf8)
  mysql_read_query_result(*mysql)
  mysql_real_connect(*mysql, host.p-utf8, user.p-utf8, passwd.p-utf8, db.p-utf8, port.l, unix_socket.p-utf8, flags.l)
  mysql_real_escape_string(*mysql, *strTo, strFrom.p-utf8, length.l)
  mysql_real_query(*mysql, query.p-utf8, length.l)
  mysql_refresh(*mysql, Options.l)
  mysql_reload(*mysql)
  mysql_rollback(*mysql)
  mysql_row_seek(*mysql, offset.l)
  mysql_row_tell(*result)
  mysql_select_db(*mysql, db.p-utf8)
  mysql_store_result(*mysql)
EndImport

;-
;- Private - MySQL Interface
;-

Structure IMYSQL_VTABLE
  
  *host
  *proto
  *client_long
  *client_string
  *server_long
  *server_string
  
  *affected_rows
  *error
  *escape_string
  
  *field
  *field_length
  *field_length_max
  *field_name
  *field_reset
  *field_type
  *field_type_string
  
  *free
  
  *GetDate 
  *GetDateTime 
  *GetDouble 
  *GetFloat 
  *GetLong 
  *GetQuad 
  *GetString 
  *GetTime 
  
  *get_date
  *get_date_string
  *get_datetime
  *get_datetime_string
  *get_double
  *get_float
  *get_long
  *get_quad
  *get_string
  *get_time
  *get_time_string
  
  *info
  *insert_id
  
  *num_fields
  *num_rows
  
  *ping
  
  *query
  *query_from_file
  *query_xml
  *query_xml_from_file
  
  *row
  *selectdb
  
  *update
  *update_from_file

  ;added 24/07/09
  *autocommit
  *commit
EndStructure
Structure SMYSQL
  *vt.IMYSQL_VTABLE
  *link
  *result
  *row.MYSQL_ROW
  *field.MYSQL_FIELD
EndStructure
Interface IMYSQL
  
  host.s()
  proto.l()
  client_long.l()
  client_string.s()
  server_long.l()
  server_string.s()
  
  affected_rows.l()
  error.s()
  escape_string.s(string.s)
  field.l()
  field_length.l()
  field_length_max.l()
  field_name.s()
  field_reset.l()
  field_type.l()
  field_type_string.s()
  free.l()
  GetDate.l(name.s)
  GetDateTime.l(name.s)
  GetDouble.d(name.s)
  GetFloat.f(name.s)
  GetLong.l(name.s)
  GetQuad.q(name.s)
  GetString.s(name.s)
  GetTime.l(name.s)
  get_date.l(column.l = 0)
  get_date_string.s(column.l = 0)
  get_datetime.l(column.l = 0)
  get_datetime_string.s(column.l = 0)
  get_double.d(column.l = 0)
  get_float.f(column.l = 0)
  get_long.l(column.l = 0)
  get_quad.q(column.l = 0)
  get_string.s(column.l = 0)
  get_time.l(column.l = 0)
  get_time_string.s(column.l = 0)
  info.s()
  insert_id.l()
  num_fields.l()
  num_rows.l()
  ping.l()
  query.l(query.s)
  query_from_file.l(fileIn.s)
  query_xml(query.s, fileOut.s, table.l = #False, db.l = #False)
  query_xml_from_file(fileIn.s, fileOut.s, table.l = #False, db.l = #False)
  row.l()
  selectdb.l(database.s)
  update.l(query.s)
  update_from_file.l(fileIn.s)
  ;added 24/07/09
  autocommit(mode.l = #True)
  commit.l()
EndInterface

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 

Procedure.s mysql_name_string(*field.MYSQL_FIELD, db.l, table.l)
  
  Protected result.s
  
  If db
    result + *field\db + "."
  EndIf
  
  If table
    result + *field\table + "."
  EndIf
  
  ProcedureReturn result + *field\name
  
EndProcedure
Procedure.s mysql_type_string(Type.l)
  
  Select Type
    Case #MYSQL_TYPE_DECIMAL:     ProcedureReturn "decimal"
    Case #MYSQL_TYPE_TINY:        ProcedureReturn "tiny"
    Case #MYSQL_TYPE_SHORT:       ProcedureReturn "short"
    Case #MYSQL_TYPE_LONG:        ProcedureReturn "long"
    Case #MYSQL_TYPE_FLOAT:       ProcedureReturn "float"
    Case #MYSQL_TYPE_DOUBLE:      ProcedureReturn "double"
    Case #MYSQL_TYPE_NULL:        ProcedureReturn "null"
    Case #MYSQL_TYPE_TIMESTAMP:   ProcedureReturn "timestamp"
    Case #MYSQL_TYPE_LONGLONG:    ProcedureReturn "longlong"
    Case #MYSQL_TYPE_INT24:       ProcedureReturn "int24"
    Case #MYSQL_TYPE_DATE:        ProcedureReturn "date"
    Case #MYSQL_TYPE_TIME:        ProcedureReturn "time"
    Case #MYSQL_TYPE_DATETIME:    ProcedureReturn "datetime"
    Case #MYSQL_TYPE_YEAR:        ProcedureReturn "year"
    Case #MYSQL_TYPE_NEWDATE:     ProcedureReturn "newdate"
    Case #MYSQL_TYPE_VARCHAR:     ProcedureReturn "varchar"
    Case #MYSQL_TYPE_BIT:         ProcedureReturn "bit"
    Case #MYSQL_TYPE_NEWDECIMAL:  ProcedureReturn "newdecimal"
    Case #MYSQL_TYPE_ENUM:        ProcedureReturn "enum"
    Case #MYSQL_TYPE_SET:         ProcedureReturn "set"
    Case #MYSQL_TYPE_TINY_BLOB:   ProcedureReturn "tinyblob"
    Case #MYSQL_TYPE_MEDIUM_BLOB: ProcedureReturn "mediumblob"
    Case #MYSQL_TYPE_LONG_BLOB:   ProcedureReturn "longblob"
    Case #MYSQL_TYPE_BLOB:        ProcedureReturn "blob"
    Case #MYSQL_TYPE_VAR_STRING:  ProcedureReturn "varstring"
    Case #MYSQL_TYPE_STRING:      ProcedureReturn "string"
    Case #MYSQL_TYPE_GEOMETRY:    ProcedureReturn "geometry"
  EndSelect
  
  ProcedureReturn "unknown"
  
EndProcedure

Procedure.l db_affected_rows(*this.SMYSQL)
  
  If *this And *this\link 
    mysql_affected_rows(*this\link) 
  EndIf
  
EndProcedure
Procedure.s db_error(*this.SMYSQL)
  
  If *this And *this\link
    
    If mysql_error(*this\link)
      ;ProcedureReturn PeekS(mysql_error(*this\link))
      ProcedureReturn PeekS_Utf8(mysql_error(*this\link))
    EndIf
    
  EndIf
  
EndProcedure
Procedure.s db_escape_string(*this.SMYSQL, string.s)
  
  Protected result.s
  
  If *this And *this\link 
    
    result = Space((Len(string) + 2) * 2)
    result = ReplaceString(Left(result, mysql_real_escape_string(*this\link, @result, string, Len(string))), #TAB$, "\t")
    
    ProcedureReturn result
    
  EndIf
  
EndProcedure

Procedure.l db_field(*this.SMYSQL)
  
  If *this And *this\result
    
    *this\field = mysql_fetch_field(*this\result)
    
    ProcedureReturn *this\field
    
  EndIf
  
EndProcedure
Procedure.l db_field_length(*this.SMYSQL)
  
  If *this And *this\field
    ProcedureReturn *this\field\length
  EndIf
  
EndProcedure
Procedure.l db_field_length_max(*this.SMYSQL)
  
  If *this And *this\field
    ProcedureReturn *this\field\max_length
  EndIf
  
EndProcedure
Procedure.s db_field_name(*this.SMYSQL)
  
  If *this And *this\field
    ProcedureReturn *this\field\name
  EndIf
  
EndProcedure
Procedure.l db_field_reset(*this.SMYSQL)
  
  If *this And *this\result
    ProcedureReturn mysql_field_seek(*this\result, 0)
  EndIf
  
EndProcedure
Procedure.l db_field_type(*this.SMYSQL)
  
  If *this And *this\field
    ProcedureReturn *this\field\type
  EndIf
  
EndProcedure
Procedure.s db_field_type_string(*this.SMYSQL)
  
  If *this And *this\field
    ProcedureReturn mysql_type_string(*this\field\type)
  EndIf
  
EndProcedure

Procedure.l db_free(*mysql.SMYSQL)
  
  If *mysql
    
    If *mysql\result
      mysql_free_result(*mysql\result)
    EndIf
    
    If *mysql\link
      mysql_close(*mysql\link) 
    EndIf
    
  EndIf
  
EndProcedure

Procedure.l db_GetDate(*this.SMYSQL, name.s)
  
  Protected *field.MYSQL_FIELD, nFields.l, i.l
  
  If *this\result And *this\row
    
    nFields = mysql_num_fields(*this\result)
    
    If nFields
      
      mysql_field_seek(*this\result, 0) 
      
      For i = 0 To nFields - 1
        
        *field = mysql_fetch_field(*this\result)
        
        If *field\name = name
          ProcedureReturn ParseDate("%yyyy-%mm-%dd", *this\row\field[i])
        EndIf
        
      Next
      
    EndIf
    
  EndIf
  
EndProcedure
Procedure.l db_GetDateTime(*this.SMYSQL, name.s)
  
  Protected *field.MYSQL_FIELD, nFields.l, i.l
  
  If *this\result And *this\row
    
    nFields = mysql_num_fields(*this\result)
    
    If nFields
      
      mysql_field_seek(*this\result, 0) 
      
      For i = 0 To nFields - 1
        
        *field = mysql_fetch_field(*this\result)
        
        If *field\name = name
          ProcedureReturn ParseDate("%yyyy-%mm-%dd %hh:%ii:%ss", *this\row\field[i])
        EndIf
        
      Next
      
    EndIf
    
  EndIf
  
EndProcedure
Procedure.d db_GetDouble(*this.SMYSQL, name.s)
  
  Protected *field.MYSQL_FIELD, nFields.l, i.l
  
  If *this\result And *this\row
    
    nFields = mysql_num_fields(*this\result)
    
    If nFields
      
      mysql_field_seek(*this\result, 0) 
      
      For i = 0 To nFields - 1
        
        *field = mysql_fetch_field(*this\result)
        
        If *field\name = name
          ProcedureReturn ValD(*this\row\field[i])
        EndIf
        
      Next
      
    EndIf
    
  EndIf
  
EndProcedure
Procedure.f db_GetFloat(*this.SMYSQL, name.s)
  
  Protected *field.MYSQL_FIELD, nFields.l, i.l
  
  If *this\result And *this\row
    
    nFields = mysql_num_fields(*this\result)
    
    If nFields
      
      mysql_field_seek(*this\result, 0) 
      
      For i = 0 To nFields - 1
        
        *field = mysql_fetch_field(*this\result)
        
        If *field\name = name
          ProcedureReturn ValF(*this\row\field[i])
        EndIf
        
      Next
      
    EndIf
    
  EndIf
  
EndProcedure
Procedure.l db_GetLong(*this.SMYSQL, name.s)
  
  Protected *field.MYSQL_FIELD, nFields.l, i.l
  
  If *this\result And *this\row
    
    nFields = mysql_num_fields(*this\result)
    
    If nFields
      
      mysql_field_seek(*this\result, 0) 
      
      For i = 0 To nFields - 1
        
        *field = mysql_fetch_field(*this\result)
        
        If *field\name = name
          ProcedureReturn Val(*this\row\field[i])
        EndIf
        
      Next
      
    EndIf
    
  EndIf
  
EndProcedure
Procedure.q db_GetQuad(*this.SMYSQL, name.s)
  
  Protected *field.MYSQL_FIELD, nFields.l, i.l
  
  If *this\result And *this\row
    
    nFields = mysql_num_fields(*this\result)
    
    If nFields
      
      mysql_field_seek(*this\result, 0) 
      
      For i = 0 To nFields - 1
        
        *field = mysql_fetch_field(*this\result)
        
        If *field\name = name
          ;ProcedureReturn ValQ(*this\row\field[i])
          ProcedureReturn Val(*this\row\field[i])
        EndIf
        
      Next
      
    EndIf
    
  EndIf
  
EndProcedure
Procedure.s db_GetString(*this.SMYSQL, name.s)
  
  Protected *field.MYSQL_FIELD, nFields.l, i.l
  
  If *this\result And *this\row
    
    nFields = mysql_num_fields(*this\result)
    
    If nFields
      
      mysql_field_seek(*this\result, 0)
      
      For i = 0 To nFields - 1
        
        *field = mysql_fetch_field(*this\result)
        
        If *field\name = name
          ProcedureReturn *this\row\field[i]
        EndIf
        
      Next
      
    EndIf
    
  EndIf
  
EndProcedure
Procedure.l db_GetTime(*this.SMYSQL, name.s)
  
  Protected *field.MYSQL_FIELD, nFields.l, i.l
  
  If *this\result And *this\row
    
    nFields = mysql_num_fields(*this\result)
    
    If nFields
      
      mysql_field_seek(*this\result, 0) 
      
      For i = 0 To nFields - 1
        
        *field = mysql_fetch_field(*this\result)
        
        If *field\name = name
          ProcedureReturn ParseDate("%hh:%ii:%ss", *this\row\field[i])
        EndIf
        
      Next
      
    EndIf
    
  EndIf
  
EndProcedure

Procedure.l db_get_date(*this.SMYSQL, column.l = 0)
  
  If *this And *this\row 
    ProcedureReturn ParseDate("%yyyy-%mm-%dd", *this\row\field[column])
  EndIf
  
EndProcedure
Procedure.s db_get_date_string(*this.SMYSQL, column.l = 0)
  
  If *this And *this\row 
    Protected date.l = ParseDate("%yyyy-%mm-%dd", *this\row\field[column])
    If date <> -1
      ProcedureReturn FormatDate("%dd-%mm-%yyyy", date)
    EndIf
  EndIf
  
EndProcedure
Procedure.l db_get_datetime(*this.SMYSQL, column.l = 0)
  
  If *this And *this\row 
    ProcedureReturn ParseDate("%yyyy-%mm-%dd %hh:%ii:%ss", *this\row\field[column])
  EndIf
  
EndProcedure
Procedure.s db_get_datetime_string(*this.SMYSQL, column.l = 0)
  
  If *this And *this\row 
    Protected datetime.l = ParseDate("%yyyy-%mm-%dd %hh:%ii:%ss", *this\row\field[column])
    If datetime <> -1
      ProcedureReturn FormatDate("%dd-%mm-%yyyy %hh:%ii:%ss", datetime)
    EndIf
  EndIf
  
EndProcedure
Procedure.d db_get_double(*this.SMYSQL, column.l = 0)
  
  If *this And *this\row 
    ProcedureReturn ValD(*this\row\field[column])
  EndIf
  
EndProcedure
Procedure.f db_get_float(*this.SMYSQL, column.l = 0)
  
  If *this And *this\row 
    ProcedureReturn ValF(*this\row\field[column])
  EndIf
  
EndProcedure
Procedure.l db_get_long(*this.SMYSQL, column.l = 0)
  
  If *this And *this\row 
    ProcedureReturn Val(*this\row\field[column])
  EndIf
  
EndProcedure
Procedure.q db_get_quad(*this.SMYSQL, column.l = 0)
  
  If *this And *this\row 
    ;ProcedureReturn ValQ(*this\row\field[column])
    ProcedureReturn Val(*this\row\field[column])
  EndIf
  
EndProcedure
Procedure.s db_get_string(*this.SMYSQL, column.l = 0)
  
  If *this And *this\row 
    ProcedureReturn *this\row\field[column]
  EndIf
  
EndProcedure
Procedure.l db_get_time(*this.SMYSQL, column.l = 0)
  
  If *this And *this\row 
    ProcedureReturn ParseDate("%hh:%ii:%ss", *this\row\field[column])
  EndIf
  
EndProcedure
Procedure.s db_get_time_string(*this.SMYSQL, column.l = 0)
  
  If *this And *this\row 
    ProcedureReturn *this\row\field[column]
  EndIf
  
EndProcedure

Procedure.s db_info(*this.SMYSQL)
  
  If *this And *this\link 
    
    If mysql_info(*this\link) 
      ;ProcedureReturn PeekS(mysql_info(*this\link))
      ProcedureReturn PeekS_Utf8(mysql_info(*this\link))
    EndIf
    
  EndIf
  
EndProcedure
Procedure.l db_insert_id(*this.SMYSQL)
  
  If *this And *this\link 
    mysql_insert_id(*this\link) 
  EndIf
  
EndProcedure
Procedure.l db_num_fields(*this.SMYSQL)
  
  If *this And *this\result
    ProcedureReturn mysql_num_fields(*this\result)
  EndIf
  
EndProcedure
Procedure.l db_num_rows(*this.SMYSQL)
  
  If *this And *this\result
    ProcedureReturn mysql_num_rows(*this\result)
  EndIf
  
EndProcedure
Procedure.l db_ping(*this.SMYSQL)
  
  If *this And *this\link
    
    If mysql_ping(*this\link) = #MYSQL_NOERROR
      ProcedureReturn #True
    EndIf
    
  EndIf
  
EndProcedure
Procedure.l db_query(*this.SMYSQL, query.s)
  
  If *this And *this\link
    
    If *this\result
      mysql_free_result(*this\result)
    EndIf
    
    If mysql_real_query(*this\link, query, Len(query)) = #MYSQL_NOERROR
    ;If mysql_query(*this\link, query) = #MYSQL_NOERROR
      
      *this\result = mysql_store_result(*this\link)

      If *this\result
        ProcedureReturn #True
      EndIf
      
    EndIf
    
  EndIf
  
EndProcedure

Procedure.l db_query_from_file(*this.SMYSQL, fileIn.s)
  
  Protected result.l, file.l, query.s
  
  If *this And *this\link
    
    If *this\result
      mysql_free_result(*this\result)
    EndIf
    
    file = ReadFile(#PB_Any, fileIn)
    
    If file
      
      query = Space(Lof(file))
      
      If ReadData(file, @query, Lof(file)) = Lof(file)
        
        If mysql_real_query(*this\link, query, Len(query)) = #MYSQL_NOERROR
          
          *this\result = mysql_store_result(*this\link)
          
          If *this\result
            result = #True
          EndIf
          
        EndIf
        
      EndIf
      
      CloseFile(file)
      
    EndIf
    
  EndIf
  
  ProcedureReturn result
  
EndProcedure
Procedure.l db_query_xml(*this.SMYSQL, query.s, fileOut.s, table.l = #False, db.l = #False)
  
  Protected file.l, result.l, *result
  Protected i.l, num_rows.l, *row.MYSQL_ROW
  Protected j.l, num_fields.l, *field.MYSQL_FIELD
  
  If *this And *this\link
    
    If mysql_real_query(*this\link, query, Len(query)) = #MYSQL_NOERROR
      
      *result = mysql_store_result(*this\link)
      
      If *result
        
        file = CreateFile(#PB_Any, fileOut)
        
        If file
          
          num_rows   = mysql_num_rows(*result)
          num_fields = mysql_num_fields(*result)
          
          WriteStringN(file, "<?xml version='1.0' ?>")
          WriteStringN(file, "<mysql>")
          WriteStringN(file, "  <date>" + FormatDate("%yyyy-%mm-%dd %hh:%ii:%ss", Date()) + "</date>")
          WriteStringN(file, "  <query>" + db_escape_string(*this, query) + "</query>")
          WriteStringN(file, "  <fields count='" + Str(num_fields) + "'>")
          
          For j = 0 To num_fields - 1
            *field = mysql_fetch_field(*result)
            WriteStringN(file, "    <field id='" + Str(j+1) + "' type='"   + mysql_type_string(*field\Type) + "' length='" + Str(*field\length) + "' name='" + mysql_name_string(*field, db, table) + " />")
          Next j
          
          WriteStringN(file, "  </fields>")
          WriteStringN(file, "  <rows count='" + Str(num_rows) + "'>")
          
          For i = 0 To num_rows - 1
            
            mysql_field_seek(*result, 0)
            *row = mysql_fetch_row(*result)
            WriteStringN(file, "    <row id='" + Str(i+1) + "'>")
            
            For j = 0 To num_fields - 1
              *field = mysql_fetch_field(*result)
              WriteString (file, "      <" + mysql_name_string(*field, db, table) + ">")
              WriteString (file, db_escape_string(*this, *row\field[j]))
              WriteStringN(file, "</" + mysql_name_string(*field, db, table) + ">")
            Next j
            
            WriteStringN(file, "    </row>")
            
          Next i
          
          WriteStringN(file, "  </rows>")
          WriteStringN(file, "</mysql>")
          CloseFile(file)
          result = #True
          
        EndIf
        
        mysql_free_result(*result)
        
      EndIf
      
    EndIf
    
  EndIf
  
  ProcedureReturn result
  
EndProcedure
Procedure.l db_query_xml_from_file(*this.SMYSQL, fileIn.s, fileOut.s, table.l = #False, db.l = #False)
  
  ;**** to do
  
EndProcedure
Procedure.l db_row(*this.SMYSQL)
  
  If *this And *this\result
    
    *this\row = mysql_fetch_row(*this\result)
    
    ProcedureReturn *this\row
    
  EndIf
  
EndProcedure
Procedure.l db_selectdb(*this.SMYSQL, database.s)
  
  If *this And *this\link And (mysql_select_db(*this\link, database) = #MYSQL_NOERROR)
    ProcedureReturn #True
  EndIf
  
EndProcedure
Procedure.l db_update(*this.SMYSQL, query.s)
  
  If *this And *this\link
    
    If mysql_real_query(*this\link, query, Len(query)) = #MYSQL_NOERROR
      ProcedureReturn #True
    EndIf
    
  EndIf
  
EndProcedure
Procedure.l db_update_from_file(*this.SMYSQL, fileIn.s)
  
  Protected result.l, file.l, query.s
  
  If *this And *this\link
    
    file = ReadFile(#PB_Any, fileIn)
    
    If file
      
      query = Space(Lof(file))
      
      If ReadData(file, @query, Lof(file)) = Lof(file)
        If mysql_real_query(*this\link, query, Len(query)) = #MYSQL_NOERROR
          result = #True
        EndIf
      EndIf
      
      CloseFile(file)
      
    EndIf
    
  EndIf
  
  ProcedureReturn result
  
EndProcedure

Procedure.s db_host(*this.SMYSQL)
  
  If *this And *this\link
    If mysql_get_host_info(*this\link)
      ;ProcedureReturn PeekS(mysql_get_host_info(*this\link))
      ProcedureReturn PeekS_Utf8(mysql_get_host_info(*this\link))
    EndIf
  EndIf
  
EndProcedure
Procedure.l db_proto(*this.SMYSQL)
  
  If *this And *this\link
    ProcedureReturn mysql_get_proto_info(*this\link)
  EndIf
  
EndProcedure
Procedure.l db_client_long(*this.SMYSQL)
  
  If *this
    ProcedureReturn mysql_get_client_version()
  EndIf
  
EndProcedure
Procedure.s db_client_string(*this.SMYSQL)
  
  If *this And mysql_get_client_info()
    ;ProcedureReturn PeekS(mysql_get_client_info())
    ProcedureReturn PeekS_Utf8(mysql_get_client_info())
  EndIf
  
EndProcedure
Procedure.l db_server_long(*this.SMYSQL)
  
  If *this And *this\link
    ProcedureReturn mysql_get_server_version(*this\link)
  EndIf
  
EndProcedure
Procedure.s db_server_string(*this.SMYSQL)
  
  If *this And *this\link
    If mysql_get_server_info(*this\link)
      ;ProcedureReturn PeekS(mysql_get_server_info(*this\link))
      ProcedureReturn PeekS_Utf8(mysql_get_server_info(*this\link))
    EndIf
  EndIf
  
EndProcedure

; added 24/07/09
Procedure.l db_autocommit(*this.SMYSQL, mode.l)
  If *this And *this\link
    
    If mysql_autocommit(*this\link, mode) = #MYSQL_NOERROR
      ProcedureReturn #True
    EndIf
    
  EndIf
EndProcedure

Procedure.l db_commit(*this.SMYSQL)
  If *this And *this\link
    
    If mysql_commit(*this\link) = #MYSQL_NOERROR
      ProcedureReturn #True
    EndIf
    
  EndIf
EndProcedure

;-
;- Public - MySQL Interface
;-

ProcedureDLL.l mysql(host.s = "localhost", user.s = "root", pwd.s = "", db.s = "", port.l = 3306, flags.l = #Null)
  
  Protected *this.SMYSQL = AllocateMemory(SizeOf(SMYSQL))
  
  If *this
    
    *this\vt = AllocateMemory(SizeOf(IMYSQL_VTABLE))
    
    If *this\vt
      
      *this\link = mysql_init(#Null)
      
      If *this\link
        
        If mysql_real_connect(*this\link, host, user, pwd, db, port, "NULL", flags) = *this\link
          
          *this\vt\host                = @db_host() 
          *this\vt\proto               = @db_proto() 
          *this\vt\client_long         = @db_client_long() 
          *this\vt\client_string       = @db_client_string() 
          *this\vt\server_long         = @db_server_long() 
          *this\vt\server_string       = @db_server_string() 
          
          *this\vt\affected_rows       = @db_affected_rows() 
          *this\vt\error               = @db_error() 
          *this\vt\escape_string       = @db_escape_string() 
          *this\vt\field               = @db_field() 
          *this\vt\field_length        = @db_field_length() 
          *this\vt\field_length_max    = @db_field_length_max() 
          *this\vt\field_name          = @db_field_name() 
          *this\vt\field_reset         = @db_field_reset() 
          *this\vt\field_type          = @db_field_type() 
          *this\vt\field_type_string   = @db_field_type_string() 
          *this\vt\free                = @db_free() 
          *this\vt\GetDate             = @db_GetDate()
          *this\vt\GetDateTime         = @db_GetDateTime()
          *this\vt\GetDouble           = @db_GetDouble()
          *this\vt\GetFloat            = @db_GetFloat()
          *this\vt\GetLong             = @db_GetLong()
          *this\vt\GetQuad             = @db_GetQuad()
          *this\vt\GetString           = @db_GetString()
          *this\vt\GetTime             = @db_GetTime()
          *this\vt\get_date            = @db_get_date() 
          *this\vt\get_date_string     = @db_get_date_string() 
          *this\vt\get_datetime        = @db_get_datetime() 
          *this\vt\get_datetime_string = @db_get_datetime_string() 
          *this\vt\get_double          = @db_get_double() 
          *this\vt\get_float           = @db_get_float() 
          *this\vt\get_long            = @db_get_long() 
          *this\vt\get_quad            = @db_get_quad() 
          *this\vt\get_string          = @db_get_string() 
          *this\vt\get_time            = @db_get_time()
          *this\vt\get_time_string     = @db_get_time_string()
          *this\vt\info                = @db_info() 
          *this\vt\insert_id           = @db_insert_id() 
          *this\vt\num_fields          = @db_num_fields() 
          *this\vt\num_rows            = @db_num_rows() 
          *this\vt\ping                = @db_ping() 
          *this\vt\query               = @db_query() 
          *this\vt\query_from_file     = @db_query_from_file() 
          *this\vt\query_xml           = @db_query_xml() 
          *this\vt\query_xml_from_file = @db_query_xml_from_file() 
          *this\vt\row                 = @db_row() 
          *this\vt\selectdb            = @db_selectdb() 
          *this\vt\update              = @db_update() 
          *this\vt\update_from_file    = @db_update_from_file() 
          *this\vt\autocommit          = @db_autocommit()
          *this\vt\commit              = @db_commit()

          ProcedureReturn *this
          
        EndIf
        
        mysql_close(*this\link) : *this\link = #Null
        
      EndIf
      
      FreeMemory(*this\vt) : *this\vt = #Null
      
    EndIf
    
    FreeMemory(*this) : *this = #Null
    
  EndIf
  
EndProcedure
ProcedureDLL.l mysql_from_ini()
  
  OpenPreferences("libmysql.ini")
  
  PreferenceGroup("CONNECTION")
  
  Protected db_host.s = ReadPreferenceString("host", "localhost")
  Protected db_user.s = ReadPreferenceString("user", "root")
  Protected db_pass.s = ReadPreferenceString("pass", #NULL$)
  Protected db_base.s = ReadPreferenceString("base", #NULL$)
  Protected db_port.l = ReadPreferenceLong  ("port", 3306)
  Protected db_opts.l = ReadPreferenceLong  ("opts", #Null)
  
  ClosePreferences()
  
  ProcedureReturn mysql(db_host, db_user, db_pass, db_base, db_port, db_opts)
  
EndProcedure

DisableExplicit

;- 
;- End Of File
;- 
Je devrais donc pouvoir faire tourner cette exemple en unicode :

Code : Tout sélectionner

IncludePath #PB_Compiler_Home + "Includes\"
XIncludeFile "libmysql_utf8.pbi"      ;Unicode ou ascii

db.IMYSQL = mysql("localhost","hotline", "", "mysql")

If db
 
  If db\query("SELECT 'Hello' AS 'f1', 'World !' AS 'f2', NOW() as 'f3', 12345.6789")
   
    While db\row()
     
      Debug db\GetString("f1")
      Debug db\GetString("f2")
     
      Debug FormatDate("%dd.%mm.%yyyy", db\GetDate("f3"))
     
      Debug db\get_double(3)
     
    Wend
   
  Else
   
    Debug db\error()
   
  EndIf
 
  db\free()
 
EndIf
Mais je n'ai aucun résultat :(
f1roe
Messages : 34
Inscription : dim. 04/sept./2005 22:10
Localisation : Lyon 3ème

Message par f1roe »

Bonjour,

J'utililise celui-ci sous windows ou Linux en unicode sans rencontrer un seul problème.


Code : Tout sélectionner

 ;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 

;Goto suite
;   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,"192.168.0.2","f1roe","b+72i39z","",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,"f1roe") <> 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 "Tables : >"+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 
;suite:
  ;*************************************************************************************************
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Message par flaith »

f1roe a écrit :Bonjour,

J'utililise celui-ci sous windows ou Linux en unicode sans rencontrer un seul problème.
Merci à toi, j'avais vu ce wrapper aussi, mais son utilisation reste assez brutale par rapport à l'approche type "oop" de Flype, ca me demanderait trop de boulot pour changer toutes les lignes utilisant le wrapper dans mon programme :)
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

salut,

J'ai noté aussi ce problème unicode sur mon include.

C'est facile néanmoins à rendre tout çà compatible.

Je vais voir et vous tiens au courant. :)
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Message par flaith »

Flype a écrit :salut,

J'ai noté aussi ce problème unicode sur mon include.

C'est facile néanmoins à rendre tout çà compatible.

Je vais voir et vous tiens au courant. :)
Cool :D
Répondre