Changeset 74
- Timestamp:
- 12/10/07 16:26:36 (1 year ago)
- Files:
-
- trunk/dbi/PreparedStatement.d (added)
- trunk/dbi/mysql/MysqlDatabase.d (modified) (4 diffs)
- trunk/dbi/mysql/MysqlPreparedStatement.d (added)
- trunk/dbi/mysql/imp.d (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dbi/mysql/MysqlDatabase.d
r70 r74 22 22 private import dbi.mysql.imp, dbi.mysql.MysqlError, dbi.mysql.MysqlResult; 23 23 24 static 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 24 41 /** 25 42 * An implementation of Database for use with MySQL databases. … … 232 249 } 233 250 234 p rivate:251 package: 235 252 MYSQL* connection; 236 253 } … … 271 288 } 272 289 } 273 290 /+ 274 291 s1("dbi.mysql.MysqlDatabase:"); 275 292 MysqlDatabase db = new MysqlDatabase(); … … 316 333 317 334 s2("close"); 318 db.close(); 319 } 320 321 } 335 db.close();+/ 336 } 337 338 } trunk/dbi/mysql/imp.d
r70 r74 8 8 9 9 extern (C): 10 version (Windows) extern (Windows): 10 11 11 12 version (Windows) { 12 13 pragma (lib, "libmysql.lib"); 13 extern (Windows):14 14 } else version (linux) { 15 15 pragma (lib, "libmysql.a"); … … 20 20 } else { 21 21 pragma (msg, "You will need to manually link in the MySQL library."); 22 } 23 24 version(MySQL_51) { 25 const uint MYSQL_VERSION = 50100; 26 } 27 else { 28 const uint MYSQL_VERSION = 50000; 22 29 } 23 30 … … 684 691 uint charsetnr; 685 692 enum_field_types type; 693 version(MySQL_51){ 694 void* extension; 695 } 686 696 }; 687 697 alias st_mysql_field MYSQL_FIELD; … … 740 750 alias st_mem_root MEM_ROOT; 741 751 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 }; 752 version(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 } 764 else { 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 } 752 775 alias st_mysql_data MYSQL_DATA; 753 776 … … 814 837 int (*local_infile_error)(void *, char *, uint); 815 838 void *local_infile_userdata; 839 version(MySQL_51) { 840 void* extension; 841 } 816 842 } 817 843 … … 919 945 920 946 my_bool *unbuffered_fetch_owner; 947 byte* info_buffer; 948 version(MySQL_51) { 949 void* extension; 950 } 921 951 }; 922 952 alias st_mysql MYSQL; … … 930 960 uint *lengths; 931 961 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 } 940 982 }; 941 983 alias st_mysql_res MYSQL_RES; … … 944 986 NET net; 945 987 char* host,user,passwd; 988 version(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 } 999 else { 946 1000 uint port; 947 1001 my_bool free_me; … … 953 1007 int net_buf_size; 954 1008 char last_error[256]; 1009 } 955 1010 }; 956 1011 alias st_mysql_manager MYSQL_MANAGER; … … 1158 1213 MYSQL_STMT_FETCH_DONE 1159 1214 }; 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 }; 1215 version(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 } 1244 else 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 } 1184 1271 alias st_mysql_bind MYSQL_BIND; 1185 1272 … … 1196 1283 MYSQL_DATA result; 1197 1284 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 } 1207 1298 uint stmt_id; 1208 1299 uint flags; … … 1229 1320 1230 1321 my_bool update_max_length; 1322 version(MySQL_51) { 1323 void* extension; 1324 } 1231 1325 }; 1232 1326 alias st_mysql_stmt MYSQL_STMT; … … 1329 1423 uint net_safe_read(MYSQL* mysql); 1330 1424 1425 const uint NOT_NULL_FLAG = 1; /* Field can't be NULL */ 1426 const uint PRI_KEY_FLAG = 2; /* Field is part of a primary key */ 1427 const uint UNIQUE_KEY_FLAG = 4; /* Field is part of a unique key */ 1428 const uint MULTIPLE_KEY_FLAG = 8; /* Field is part of a key */ 1429 const uint BLOB_FLAG = 16; /* Field is a blob */ 1430 const uint UNSIGNED_FLAG = 32; /* Field is unsigned */ 1431 const uint ZEROFILL_FLAG = 64; /* Field is zerofill */ 1432 const uint BINARY_FLAG = 128; /* Field is binary */ 1433 1434 const int MYSQL_NO_DATA = 100; 1435 const int MYSQL_DATA_TRUNCATED = 101; 1436 1331 1437 }
