Changeset 74

Show
Ignore:
Timestamp:
12/10/07 16:26:36 (1 year ago)
Author:
aaronc542
Message:

Adding first verison of PreparedStatement? API and MySQL implementation. Updated mysql imp.d file for compatibility with MySQL 5.1 client using build switch -version=MySQL_51 and added safe-guards against compilation against the wrong client library in MysqlDatabase?.d. Changed MYSQL* from private to package in MysqlDatabase?.d.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dbi/mysql/MysqlDatabase.d

    r70 r74  
    2222private import dbi.mysql.imp, dbi.mysql.MysqlError, dbi.mysql.MysqlResult; 
    2323 
     24static this() { 
     25    uint ver = mysql_get_client_version(); 
     26    if(ver < 50000) { 
     27        throw new Exception("Unsupported MySQL client version.  Please compile using at least version 5.0 of the MySQL client libray."); 
     28    } 
     29    else if(ver < 50100) { 
     30        if(MYSQL_VERSION != 50000) { 
     31            throw new Exception("You are linking against version 5.0 of the MySQL client library but you have a build switch turned on for a different version (such as MySQL_51)."); 
     32        } 
     33    } 
     34    else { 
     35        if(MYSQL_VERSION != 50100) { 
     36            throw new Exception("You are linking against version 5.1 (or higher) of the MySQL client library so you need to use the build switch '-version=MySQL_51'."); 
     37        } 
     38    } 
     39} 
     40 
    2441/** 
    2542 * An implementation of Database for use with MySQL databases. 
     
    232249        } 
    233250 
    234     private: 
     251    package: 
    235252    MYSQL* connection; 
    236253} 
     
    271288        } 
    272289    } 
    273  
     290/+ 
    274291    s1("dbi.mysql.MysqlDatabase:"); 
    275292    MysqlDatabase db = new MysqlDatabase(); 
     
    316333 
    317334    s2("close"); 
    318     db.close(); 
    319 } 
    320  
    321 } 
     335    db.close();+/ 
     336} 
     337 
     338} 
  • trunk/dbi/mysql/imp.d

    r70 r74  
    88 
    99extern (C): 
     10version (Windows) extern (Windows): 
    1011 
    1112version (Windows) { 
    1213    pragma (lib, "libmysql.lib"); 
    13     extern (Windows): 
    1414} else version (linux) { 
    1515    pragma (lib, "libmysql.a"); 
     
    2020} else { 
    2121    pragma (msg, "You will need to manually link in the MySQL library."); 
     22} 
     23 
     24version(MySQL_51) { 
     25    const uint MYSQL_VERSION = 50100; 
     26} 
     27else { 
     28    const uint MYSQL_VERSION = 50000; 
    2229} 
    2330 
     
    684691  uint charsetnr; 
    685692  enum_field_types type; 
     693  version(MySQL_51){ 
     694      void* extension; 
     695  } 
    686696}; 
    687697alias st_mysql_field MYSQL_FIELD; 
     
    740750alias st_mem_root MEM_ROOT; 
    741751 
    742  
    743 struct st_mysql_data { 
    744   my_ulonglong rows; 
    745   uint fields; 
    746   MYSQL_ROWS *data; 
    747   MEM_ROOT alloc; 
    748  
    749   MYSQL_ROWS **prev_ptr; 
    750  
    751 }; 
     752version(MySQL_51) { 
     753    struct st_mysql_data { 
     754        MYSQL_ROWS *data; 
     755        //embedded_query_result *embedded_info; 
     756        void* embedded_info; 
     757        MEM_ROOT alloc; 
     758        my_ulonglong rows; 
     759        uint fields; 
     760        void* extension; 
     761     
     762        };   
     763
     764else { 
     765    struct st_mysql_data { 
     766      my_ulonglong rows; 
     767      uint fields; 
     768      MYSQL_ROWS *data; 
     769      MEM_ROOT alloc; 
     770     
     771      MYSQL_ROWS **prev_ptr; 
     772     
     773    }; 
     774
    752775alias st_mysql_data MYSQL_DATA; 
    753776 
     
    814837  int (*local_infile_error)(void *, char *, uint); 
    815838  void *local_infile_userdata; 
     839  version(MySQL_51) { 
     840      void* extension; 
     841  } 
    816842} 
    817843 
     
    919945 
    920946  my_bool *unbuffered_fetch_owner; 
     947  byte* info_buffer; 
     948  version(MySQL_51) { 
     949      void* extension; 
     950  } 
    921951}; 
    922952alias st_mysql MYSQL; 
     
    930960  uint *lengths; 
    931961  MYSQL *handle; 
    932   MEM_ROOT field_alloc; 
    933   uint field_count, current_field; 
    934   MYSQL_ROW row; 
    935   MYSQL_ROW current_row; 
    936   my_bool eof; 
    937  
    938   my_bool unbuffered_fetch_cancelled; 
    939   const st_mysql_methods *methods; 
     962  version(MySQL_51) { 
     963      const st_mysql_methods *methods; 
     964      MYSQL_ROW row; 
     965      MYSQL_ROW current_row; 
     966      MEM_ROOT field_alloc; 
     967      uint field_count, current_field; 
     968      my_bool eof; 
     969      my_bool unbuffered_fetch_cancelled;      
     970      void* extension; 
     971  } 
     972  else { 
     973      MEM_ROOT field_alloc; 
     974      uint field_count, current_field; 
     975      MYSQL_ROW row; 
     976      MYSQL_ROW current_row; 
     977      my_bool eof; 
     978 
     979      my_bool unbuffered_fetch_cancelled; 
     980      const st_mysql_methods *methods;   
     981  } 
    940982}; 
    941983alias st_mysql_res MYSQL_RES; 
     
    944986  NET net; 
    945987  char*  host,user,passwd; 
     988version(MySQL_51) { 
     989    char* net_buf,net_buf_pos,net_data_end; 
     990    uint port; 
     991    int cmd_status; 
     992    int last_errno; 
     993    int net_buf_size; 
     994    my_bool free_me; 
     995    my_bool eof; 
     996    char last_error[256]; 
     997    void* extension; 
     998} 
     999else { 
    9461000  uint port; 
    9471001  my_bool free_me; 
     
    9531007  int net_buf_size; 
    9541008  char last_error[256]; 
     1009} 
    9551010}; 
    9561011alias st_mysql_manager MYSQL_MANAGER; 
     
    11581213  MYSQL_STMT_FETCH_DONE 
    11591214}; 
    1160 struct st_mysql_bind { 
    1161   uint *length; 
    1162   my_bool *is_null; 
    1163   void *buffer; 
    1164  
    1165   my_bool *error; 
    1166   enum_field_types buffer_type; 
    1167  
    1168   uint buffer_length; 
    1169   ubyte *row_ptr; 
    1170   uint offset; 
    1171   uint length_value; 
    1172   uint param_number; 
    1173   uint pack_length; 
    1174   my_bool error_value; 
    1175   my_bool is_unsigned; 
    1176   my_bool int_data_used; 
    1177   my_bool is_null_value; 
    1178   void (*store_param_func)(NET *net, st_mysql_bind *param); 
    1179   void (*fetch_result)(st_mysql_bind *, MYSQL_FIELD *, 
    1180                        ubyte **row); 
    1181   void (*skip_result)(st_mysql_bind *, MYSQL_FIELD *, 
    1182                       ubyte **row); 
    1183 }; 
     1215version(MySQL_51) 
     1216
     1217    struct st_mysql_bind 
     1218    { 
     1219      uint      *length;          /* output length pointer */ 
     1220      my_bool   *is_null;     /* Pointer to null indicator */ 
     1221      void      *buffer;      /* buffer to get/put data */ 
     1222      /* set this if you want to track data truncations happened during fetch */ 
     1223      my_bool       *error; 
     1224      ubyte *row_ptr;         /* for the current data position */ 
     1225      void (*store_param_func)(NET *net, st_mysql_bind *param); 
     1226      void (*fetch_result)(st_mysql_bind *, MYSQL_FIELD *, 
     1227                           ubyte **row); 
     1228      void (*skip_result)(st_mysql_bind *, MYSQL_FIELD *, 
     1229                  ubyte **row); 
     1230      /* output buffer length, must be set when fetching str/binary */ 
     1231      uint buffer_length; 
     1232      uint offset;           /* offset position for char/binary fetch */ 
     1233      uint  length_value;     /* Used if length is 0 */ 
     1234      uint  param_number;     /* For null count and error messages */ 
     1235      uint  pack_length;      /* Internal length for packed data */ 
     1236      enum_field_types buffer_type; /* buffer type */ 
     1237      my_bool       error_value;      /* used if error is 0 */ 
     1238      my_bool       is_unsigned;      /* set if integer type is unsigned */ 
     1239      my_bool   long_data_used;   /* If used with mysql_send_long_data */ 
     1240      my_bool   is_null_value;    /* Used if is_null is 0 */ 
     1241      void *extension; 
     1242    } 
     1243
     1244else 
     1245
     1246    struct st_mysql_bind { 
     1247      uint *length; 
     1248      my_bool *is_null; 
     1249      void *buffer; 
     1250     
     1251      my_bool *error; 
     1252      enum_field_types buffer_type; 
     1253     
     1254      uint buffer_length; 
     1255      ubyte *row_ptr; 
     1256      uint offset; 
     1257      uint length_value; 
     1258      uint param_number; 
     1259      uint pack_length; 
     1260      my_bool error_value; 
     1261      my_bool is_unsigned; 
     1262      my_bool int_data_used; 
     1263      my_bool is_null_value; 
     1264      void (*store_param_func)(NET *net, st_mysql_bind *param); 
     1265      void (*fetch_result)(st_mysql_bind *, MYSQL_FIELD *, 
     1266                           ubyte **row); 
     1267      void (*skip_result)(st_mysql_bind *, MYSQL_FIELD *, 
     1268                          ubyte **row); 
     1269    }; 
     1270
    11841271alias st_mysql_bind MYSQL_BIND; 
    11851272 
     
    11961283  MYSQL_DATA result; 
    11971284  MYSQL_ROWS *data_cursor; 
    1198  
    1199   my_ulonglong affected_rows; 
    1200   my_ulonglong insert_id; 
    1201  
    1202  
    1203  
    1204  
    1205   int (*read_row_func)(st_mysql_stmt *stmt, 
    1206                                   ubyte **row); 
     1285  version(MySQL_51) {     
     1286      int (*read_row_func)(st_mysql_stmt *stmt, 
     1287                                      ubyte **row); 
     1288      my_ulonglong affected_rows; 
     1289      my_ulonglong insert_id; 
     1290  } 
     1291  else { 
     1292      my_ulonglong affected_rows; 
     1293      my_ulonglong insert_id; 
     1294      int (*read_row_func)(st_mysql_stmt *stmt, 
     1295                                      ubyte **row); 
     1296 
     1297  } 
    12071298  uint stmt_id; 
    12081299  uint flags; 
     
    12291320 
    12301321  my_bool update_max_length; 
     1322  version(MySQL_51) { 
     1323      void* extension; 
     1324  } 
    12311325}; 
    12321326alias st_mysql_stmt MYSQL_STMT; 
     
    13291423uint net_safe_read(MYSQL* mysql); 
    13301424 
     1425const uint NOT_NULL_FLAG = 1;       /* Field can't be NULL */ 
     1426const uint PRI_KEY_FLAG = 2;        /* Field is part of a primary key */ 
     1427const uint UNIQUE_KEY_FLAG = 4;     /* Field is part of a unique key */ 
     1428const uint MULTIPLE_KEY_FLAG = 8;       /* Field is part of a key */ 
     1429const uint BLOB_FLAG = 16;      /* Field is a blob */ 
     1430const uint UNSIGNED_FLAG = 32;      /* Field is unsigned */ 
     1431const uint ZEROFILL_FLAG = 64;      /* Field is zerofill */ 
     1432const uint BINARY_FLAG = 128;       /* Field is binary   */ 
     1433 
     1434const int MYSQL_NO_DATA = 100; 
     1435const int MYSQL_DATA_TRUNCATED = 101; 
     1436 
    13311437}