1 /* 2 * Database - Database abstraction layer for D programing language. 3 * 4 * Copyright (C) 2017 Shanghai Putao Technology Co., Ltd 5 * 6 * Developer: HuntLabs 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 12 module database.driver.mysql.binding; 13 14 version(USE_MYSQL ): 15 /* 16 * 17 */ 18 version(Windows) { 19 pragma(lib, "libmysql"); 20 } 21 else { 22 pragma(msg,"use mysqlclient in linux"); 23 pragma(lib, "mysqlclient"); 24 } 25 26 import std.stdio; 27 import std.exception; 28 import std..string; 29 import std.conv; 30 import std.typecons; 31 import core.stdc.config; 32 33 34 auto fromSQLType(uint type){return typeid(string);} 35 36 ///The MySQL server has gone away. 37 enum CR_SERVER_GONE_ERROR = 2006; 38 ///The connection to the server was lost during the query. 39 enum CR_SERVER_LOST = 2013; 40 41 extern(System) { 42 struct MYSQL; 43 struct MYSQL_RES; 44 struct MYSQL_STMT; 45 /* typedef */ alias const(char)* cstring; 46 alias ubyte my_bool; 47 48 struct MYSQL_FIELD 49 { 50 cstring name; /* Name of column */ 51 cstring org_name; /* Original column name, if an alias */ 52 cstring table; /* Table of column if column was a field */ 53 cstring org_table; /* Org table name, if table was an alias */ 54 cstring db; /* Database for table */ 55 cstring catalog; /* Catalog for table */ 56 cstring def; /* Default value (set by mysql_list_fields) */ 57 c_ulong length; /* Width of column (create length) */ 58 c_ulong max_length; /* Max width for selected set */ 59 uint name_length; 60 uint org_name_length; 61 uint table_length; 62 uint org_table_length; 63 uint db_length; 64 uint catalog_length; 65 uint def_length; 66 uint flags; /* Div flags */ 67 uint decimals; /* Number of decimals in field */ 68 uint charsetnr; /* Character set */ 69 uint type; /* Type of field. See mysql_com.h for types */ 70 // type is actually an enum btw 71 72 void* extension; 73 } 74 75 enum mysql_types 76 { 77 MYSQL_TYPE_DECIMAL, 78 MYSQL_TYPE_TINY, 79 MYSQL_TYPE_SHORT, 80 MYSQL_TYPE_LONG, 81 MYSQL_TYPE_FLOAT, 82 MYSQL_TYPE_DOUBLE, 83 MYSQL_TYPE_NULL, 84 MYSQL_TYPE_TIMESTAMP, 85 MYSQL_TYPE_LONGLONG, 86 MYSQL_TYPE_INT24, 87 MYSQL_TYPE_DATE, 88 MYSQL_TYPE_TIME, 89 MYSQL_TYPE_DATETIME, 90 MYSQL_TYPE_YEAR, 91 MYSQL_TYPE_NEWDATE, 92 MYSQL_TYPE_VARCHAR, 93 MYSQL_TYPE_BIT, 94 MYSQL_TYPE_TIMESTAMP2, 95 MYSQL_TYPE_DATETIME2, 96 MYSQL_TYPE_TIME2, 97 MYSQL_TYPE_NEWDECIMAL=246, 98 MYSQL_TYPE_ENUM=247, 99 MYSQL_TYPE_SET=248, 100 MYSQL_TYPE_TINY_BLOB=249, 101 MYSQL_TYPE_MEDIUM_BLOB=250, 102 MYSQL_TYPE_LONG_BLOB=251, 103 MYSQL_TYPE_BLOB=252, 104 MYSQL_TYPE_VAR_STRING=253, 105 MYSQL_TYPE_STRING=254, 106 MYSQL_TYPE_GEOMETRY=255 107 }; 108 109 enum MYSQL_TIMESTAMP_TYPE { 110 MYSQL_TIMESTAMP_NONE = -2, 111 MYSQL_TIMESTAMP_ERROR = -1, 112 MYSQL_TIMESTAMP_DATE = 0, 113 MYSQL_TIMESTAMP_DATETIME= 1, 114 MYSQL_TIMESTAMP_TIME = 2 115 }; 116 117 struct MYSQL_TIME { 118 uint year, month, day, hour, minute, second; 119 uint second_part; 120 my_bool neg; 121 MYSQL_TIMESTAMP_TYPE time_type; 122 }; 123 enum mysql_option 124 { 125 MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE, 126 MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP, 127 MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE, 128 MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT, 129 MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT, 130 MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, 131 MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, 132 MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT 133 }; 134 135 /* typedef */ 136 alias cstring* MYSQL_ROW; 137 138 cstring mysql_get_client_info(); 139 MYSQL* mysql_init(MYSQL*); 140 uint mysql_errno(MYSQL*); 141 cstring mysql_error(MYSQL*); 142 143 MYSQL* mysql_real_connect(MYSQL*, cstring, cstring, cstring, cstring, uint, cstring, c_ulong); 144 145 int mysql_options(MYSQL *mysql, mysql_option option, const void *arg); 146 147 int mysql_query(MYSQL*, cstring); 148 int mysql_real_query(MYSQL*, cstring,ulong); 149 int mysql_ping(MYSQL*); 150 151 void mysql_close(MYSQL*); 152 153 ulong mysql_num_rows(MYSQL_RES*); 154 uint mysql_num_fields(MYSQL_RES*); 155 bool mysql_eof(MYSQL_RES*); 156 157 ulong mysql_affected_rows(MYSQL*); 158 ulong mysql_insert_id(MYSQL*); 159 160 MYSQL_RES* mysql_store_result(MYSQL*); 161 MYSQL_RES* mysql_use_result(MYSQL*); 162 163 MYSQL_ROW mysql_fetch_row(MYSQL_RES *); 164 c_ulong* mysql_fetch_lengths(MYSQL_RES*); 165 MYSQL_FIELD* mysql_fetch_field(MYSQL_RES*); 166 MYSQL_FIELD* mysql_fetch_fields(MYSQL_RES*); 167 168 uint mysql_real_escape_string(MYSQL*, ubyte* to, cstring from, c_ulong length); 169 170 void mysql_free_result(MYSQL_RES*); 171 size_t mysql_thread_id(MYSQL* mysql); 172 173 MYSQL_STMT* mysql_stmt_init(MYSQL *); 174 my_bool mysql_stmt_close(MYSQL_STMT *); 175 int mysql_stmt_prepare(MYSQL_STMT *, cstring, size_t); 176 cstring mysql_stmt_error(MYSQL_STMT *); 177 int mysql_stmt_execute(MYSQL_STMT *); 178 179 my_bool mysql_autocommit(MYSQL *, my_bool); 180 181 int mysql_set_character_set(MYSQL *, cstring); 182 183 } 184 185