mysql.nim 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2010 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. {.push, callconv: cdecl.}
  10. when defined(nimHasStyleChecks):
  11. {.push styleChecks: off.}
  12. when defined(unix):
  13. when defined(macosx):
  14. const
  15. lib = "(libmysqlclient|libmariadbclient)(|.20|.19|.18|.17|.16|.15).dylib"
  16. else:
  17. const
  18. lib = "(libmysqlclient|libmariadbclient).so(|.20|.19|.18|.17|.16|.15)"
  19. when defined(windows):
  20. const
  21. lib = "(libmysql.dll|libmariadb.dll)"
  22. type
  23. my_bool* = bool
  24. Pmy_bool* = ptr my_bool
  25. PVIO* = pointer
  26. Pgptr* = ptr gptr
  27. gptr* = cstring
  28. Pmy_socket* = ptr my_socket
  29. my_socket* = cint
  30. PPByte* = pointer
  31. cuint* = cint
  32. # ------------ Start of declaration in "mysql_com.h" ---------------------
  33. #
  34. # ** Common definition between mysql server & client
  35. #
  36. # Field/table name length
  37. const
  38. NAME_LEN* = 64
  39. HOSTNAME_LENGTH* = 60
  40. USERNAME_LENGTH* = 16
  41. SERVER_VERSION_LENGTH* = 60
  42. SQLSTATE_LENGTH* = 5
  43. LOCAL_HOST* = "localhost"
  44. LOCAL_HOST_NAMEDPIPE* = '.'
  45. const
  46. NAMEDPIPE* = "MySQL"
  47. SERVICENAME* = "MySQL"
  48. type
  49. Enum_server_command* = enum
  50. COM_SLEEP, COM_QUIT, COM_INIT_DB, COM_QUERY, COM_FIELD_LIST, COM_CREATE_DB,
  51. COM_DROP_DB, COM_REFRESH, COM_SHUTDOWN, COM_STATISTICS, COM_PROCESS_INFO,
  52. COM_CONNECT, COM_PROCESS_KILL, COM_DEBUG, COM_PING, COM_TIME,
  53. COM_DELAYED_INSERT, COM_CHANGE_USER, COM_BINLOG_DUMP, COM_TABLE_DUMP,
  54. COM_CONNECT_OUT, COM_REGISTER_SLAVE, COM_STMT_PREPARE, COM_STMT_EXECUTE,
  55. COM_STMT_SEND_LONG_DATA, COM_STMT_CLOSE, COM_STMT_RESET, COM_SET_OPTION,
  56. COM_STMT_FETCH, COM_END
  57. {.deprecated: [Tenum_server_command: Enum_server_command].}
  58. const
  59. SCRAMBLE_LENGTH* = 20 # Length of random string sent by server on handshake;
  60. # this is also length of obfuscated password,
  61. # received from client
  62. SCRAMBLE_LENGTH_323* = 8 # length of password stored in the db:
  63. # new passwords are preceded with '*'
  64. SCRAMBLED_PASSWORD_CHAR_LENGTH* = SCRAMBLE_LENGTH * 2 + 1
  65. SCRAMBLED_PASSWORD_CHAR_LENGTH_323* = SCRAMBLE_LENGTH_323 * 2
  66. NOT_NULL_FLAG* = 1 # Field can't be NULL
  67. PRI_KEY_FLAG* = 2 # Field is part of a primary key
  68. UNIQUE_KEY_FLAG* = 4 # Field is part of a unique key
  69. MULTIPLE_KEY_FLAG* = 8 # Field is part of a key
  70. BLOB_FLAG* = 16 # Field is a blob
  71. UNSIGNED_FLAG* = 32 # Field is unsigned
  72. ZEROFILL_FLAG* = 64 # Field is zerofill
  73. BINARY_FLAG* = 128 # Field is binary
  74. # The following are only sent to new clients
  75. ENUM_FLAG* = 256 # field is an enum
  76. AUTO_INCREMENT_FLAG* = 512 # field is a autoincrement field
  77. TIMESTAMP_FLAG* = 1024 # Field is a timestamp
  78. SET_FLAG* = 2048 # field is a set
  79. NO_DEFAULT_VALUE_FLAG* = 4096 # Field doesn't have default value
  80. NUM_FLAG* = 32768 # Field is num (for clients)
  81. PART_KEY_FLAG* = 16384 # Intern; Part of some key
  82. GROUP_FLAG* = 32768 # Intern: Group field
  83. UNIQUE_FLAG* = 65536 # Intern: Used by sql_yacc
  84. BINCMP_FLAG* = 131072 # Intern: Used by sql_yacc
  85. REFRESH_GRANT* = 1 # Refresh grant tables
  86. REFRESH_LOG* = 2 # Start on new log file
  87. REFRESH_TABLES* = 4 # close all tables
  88. REFRESH_HOSTS* = 8 # Flush host cache
  89. REFRESH_STATUS* = 16 # Flush status variables
  90. REFRESH_THREADS* = 32 # Flush thread cache
  91. REFRESH_SLAVE* = 64 # Reset master info and restart slave thread
  92. REFRESH_MASTER* = 128 # Remove all bin logs in the index and truncate the index
  93. # The following can't be set with mysql_refresh()
  94. REFRESH_READ_LOCK* = 16384 # Lock tables for read
  95. REFRESH_FAST* = 32768 # Intern flag
  96. REFRESH_QUERY_CACHE* = 65536 # RESET (remove all queries) from query cache
  97. REFRESH_QUERY_CACHE_FREE* = 0x00020000 # pack query cache
  98. REFRESH_DES_KEY_FILE* = 0x00040000
  99. REFRESH_USER_RESOURCES* = 0x00080000
  100. CLIENT_LONG_PASSWORD* = 1 # new more secure passwords
  101. CLIENT_FOUND_ROWS* = 2 # Found instead of affected rows
  102. CLIENT_LONG_FLAG* = 4 # Get all column flags
  103. CLIENT_CONNECT_WITH_DB* = 8 # One can specify db on connect
  104. CLIENT_NO_SCHEMA* = 16 # Don't allow database.table.column
  105. CLIENT_COMPRESS* = 32 # Can use compression protocol
  106. CLIENT_ODBC* = 64 # Odbc client
  107. CLIENT_LOCAL_FILES* = 128 # Can use LOAD DATA LOCAL
  108. CLIENT_IGNORE_SPACE* = 256 # Ignore spaces before '('
  109. CLIENT_PROTOCOL_41* = 512 # New 4.1 protocol
  110. CLIENT_INTERACTIVE* = 1024 # This is an interactive client
  111. CLIENT_SSL* = 2048 # Switch to SSL after handshake
  112. CLIENT_IGNORE_SIGPIPE* = 4096 # IGNORE sigpipes
  113. CLIENT_TRANSACTIONS* = 8192 # Client knows about transactions
  114. CLIENT_RESERVED* = 16384 # Old flag for 4.1 protocol
  115. CLIENT_SECURE_CONNECTION* = 32768 # New 4.1 authentication
  116. CLIENT_MULTI_STATEMENTS* = 65536 # Enable/disable multi-stmt support
  117. CLIENT_MULTI_RESULTS* = 131072 # Enable/disable multi-results
  118. CLIENT_REMEMBER_OPTIONS*: int = 1 shl 31
  119. SERVER_STATUS_IN_TRANS* = 1 # Transaction has started
  120. SERVER_STATUS_AUTOCOMMIT* = 2 # Server in auto_commit mode
  121. SERVER_STATUS_MORE_RESULTS* = 4 # More results on server
  122. SERVER_MORE_RESULTS_EXISTS* = 8 # Multi query - next query exists
  123. SERVER_QUERY_NO_GOOD_INDEX_USED* = 16
  124. SERVER_QUERY_NO_INDEX_USED* = 32 # The server was able to fulfill the clients request and opened a
  125. # read-only non-scrollable cursor for a query. This flag comes
  126. # in reply to COM_STMT_EXECUTE and COM_STMT_FETCH commands.
  127. SERVER_STATUS_CURSOR_EXISTS* = 64 # This flag is sent when a read-only cursor is exhausted, in reply to
  128. # COM_STMT_FETCH command.
  129. SERVER_STATUS_LAST_ROW_SENT* = 128
  130. SERVER_STATUS_DB_DROPPED* = 256 # A database was dropped
  131. SERVER_STATUS_NO_BACKSLASH_ESCAPES* = 512
  132. ERRMSG_SIZE* = 200
  133. NET_READ_TIMEOUT* = 30 # Timeout on read
  134. NET_WRITE_TIMEOUT* = 60 # Timeout on write
  135. NET_WAIT_TIMEOUT* = 8 * 60 * 60 # Wait for new query
  136. ONLY_KILL_QUERY* = 1
  137. const
  138. MAX_TINYINT_WIDTH* = 3 # Max width for a TINY w.o. sign
  139. MAX_SMALLINT_WIDTH* = 5 # Max width for a SHORT w.o. sign
  140. MAX_MEDIUMINT_WIDTH* = 8 # Max width for a INT24 w.o. sign
  141. MAX_INT_WIDTH* = 10 # Max width for a LONG w.o. sign
  142. MAX_BIGINT_WIDTH* = 20 # Max width for a LONGLONG
  143. MAX_CHAR_WIDTH* = 255 # Max length for a CHAR column
  144. MAX_BLOB_WIDTH* = 8192 # Default width for blob
  145. type
  146. Pst_net* = ptr St_net
  147. St_net*{.final.} = object
  148. vio*: PVIO
  149. buff*: cstring
  150. buff_end*: cstring
  151. write_pos*: cstring
  152. read_pos*: cstring
  153. fd*: my_socket # For Perl DBI/dbd
  154. max_packet*: int
  155. max_packet_size*: int
  156. pkt_nr*: cuint
  157. compress_pkt_nr*: cuint
  158. write_timeout*: cuint
  159. read_timeout*: cuint
  160. retry_count*: cuint
  161. fcntl*: cint
  162. compress*: my_bool # The following variable is set if we are doing several queries in one
  163. # command ( as in LOAD TABLE ... FROM MASTER ),
  164. # and do not want to confuse the client with OK at the wrong time
  165. remain_in_buf*: int
  166. len*: int
  167. buf_length*: int
  168. where_b*: int
  169. return_status*: ptr cint
  170. reading_or_writing*: char
  171. save_char*: cchar
  172. no_send_ok*: my_bool # For SPs and other things that do multiple stmts
  173. no_send_eof*: my_bool # For SPs' first version read-only cursors
  174. no_send_error*: my_bool # Set if OK packet is already sent, and
  175. # we do not need to send error messages
  176. # Pointer to query object in query cache, do not equal NULL (0) for
  177. # queries in cache that have not stored its results yet
  178. # $endif
  179. last_error*: array[0..(ERRMSG_SIZE) - 1, char]
  180. sqlstate*: array[0..(SQLSTATE_LENGTH + 1) - 1, char]
  181. last_errno*: cuint
  182. error*: char
  183. query_cache_query*: gptr
  184. report_error*: my_bool # We should report error (we have unreported error)
  185. return_errno*: my_bool
  186. NET* = St_net
  187. PNET* = ptr NET
  188. {.deprecated: [Tst_net: St_net, TNET: NET].}
  189. const
  190. packet_error* = - 1
  191. type
  192. Enum_field_types* = enum # For backward compatibility
  193. TYPE_DECIMAL, TYPE_TINY, TYPE_SHORT, TYPE_LONG, TYPE_FLOAT, TYPE_DOUBLE,
  194. TYPE_NULL, TYPE_TIMESTAMP, TYPE_LONGLONG, TYPE_INT24, TYPE_DATE, TYPE_TIME,
  195. TYPE_DATETIME, TYPE_YEAR, TYPE_NEWDATE, TYPE_VARCHAR, TYPE_BIT,
  196. TYPE_NEWDECIMAL = 246, TYPE_ENUM = 247, TYPE_SET = 248,
  197. TYPE_TINY_BLOB = 249, TYPE_MEDIUM_BLOB = 250, TYPE_LONG_BLOB = 251,
  198. TYPE_BLOB = 252, TYPE_VAR_STRING = 253, TYPE_STRING = 254,
  199. TYPE_GEOMETRY = 255
  200. {.deprecated: [Tenum_field_types: Enum_field_types].}
  201. const
  202. CLIENT_MULTI_QUERIES* = CLIENT_MULTI_STATEMENTS
  203. FIELD_TYPE_DECIMAL* = TYPE_DECIMAL
  204. FIELD_TYPE_NEWDECIMAL* = TYPE_NEWDECIMAL
  205. FIELD_TYPE_TINY* = TYPE_TINY
  206. FIELD_TYPE_SHORT* = TYPE_SHORT
  207. FIELD_TYPE_LONG* = TYPE_LONG
  208. FIELD_TYPE_FLOAT* = TYPE_FLOAT
  209. FIELD_TYPE_DOUBLE* = TYPE_DOUBLE
  210. FIELD_TYPE_NULL* = TYPE_NULL
  211. FIELD_TYPE_TIMESTAMP* = TYPE_TIMESTAMP
  212. FIELD_TYPE_LONGLONG* = TYPE_LONGLONG
  213. FIELD_TYPE_INT24* = TYPE_INT24
  214. FIELD_TYPE_DATE* = TYPE_DATE
  215. FIELD_TYPE_TIME* = TYPE_TIME
  216. FIELD_TYPE_DATETIME* = TYPE_DATETIME
  217. FIELD_TYPE_YEAR* = TYPE_YEAR
  218. FIELD_TYPE_NEWDATE* = TYPE_NEWDATE
  219. FIELD_TYPE_ENUM* = TYPE_ENUM
  220. FIELD_TYPE_SET* = TYPE_SET
  221. FIELD_TYPE_TINY_BLOB* = TYPE_TINY_BLOB
  222. FIELD_TYPE_MEDIUM_BLOB* = TYPE_MEDIUM_BLOB
  223. FIELD_TYPE_LONG_BLOB* = TYPE_LONG_BLOB
  224. FIELD_TYPE_BLOB* = TYPE_BLOB
  225. FIELD_TYPE_VAR_STRING* = TYPE_VAR_STRING
  226. FIELD_TYPE_STRING* = TYPE_STRING
  227. FIELD_TYPE_CHAR* = TYPE_TINY
  228. FIELD_TYPE_INTERVAL* = TYPE_ENUM
  229. FIELD_TYPE_GEOMETRY* = TYPE_GEOMETRY
  230. FIELD_TYPE_BIT* = TYPE_BIT # Shutdown/kill enums and constants
  231. # Bits for THD::killable.
  232. SHUTDOWN_KILLABLE_CONNECT* = chr(1 shl 0)
  233. SHUTDOWN_KILLABLE_TRANS* = chr(1 shl 1)
  234. SHUTDOWN_KILLABLE_LOCK_TABLE* = chr(1 shl 2)
  235. SHUTDOWN_KILLABLE_UPDATE* = chr(1 shl 3)
  236. type
  237. Enum_shutdown_level* = enum
  238. SHUTDOWN_DEFAULT = 0, SHUTDOWN_WAIT_CONNECTIONS = 1,
  239. SHUTDOWN_WAIT_TRANSACTIONS = 2, SHUTDOWN_WAIT_UPDATES = 8,
  240. SHUTDOWN_WAIT_ALL_BUFFERS = 16, SHUTDOWN_WAIT_CRITICAL_BUFFERS = 17,
  241. KILL_QUERY = 254, KILL_CONNECTION = 255
  242. Enum_cursor_type* = enum # options for mysql_set_option
  243. CURSOR_TYPE_NO_CURSOR = 0, CURSOR_TYPE_READ_ONLY = 1,
  244. CURSOR_TYPE_FOR_UPDATE = 2, CURSOR_TYPE_SCROLLABLE = 4
  245. Enum_mysql_set_option* = enum
  246. OPTION_MULTI_STATEMENTS_ON, OPTION_MULTI_STATEMENTS_OFF
  247. {.deprecated: [Tenum_shutdown_level: Enum_shutdown_level,
  248. Tenum_cursor_type: Enum_cursor_type,
  249. Tenum_mysql_set_option: Enum_mysql_set_option].}
  250. proc my_net_init*(net: PNET, vio: PVIO): my_bool{.cdecl, dynlib: lib,
  251. importc: "my_net_init".}
  252. proc my_net_local_init*(net: PNET){.cdecl, dynlib: lib,
  253. importc: "my_net_local_init".}
  254. proc net_end*(net: PNET){.cdecl, dynlib: lib, importc: "net_end".}
  255. proc net_clear*(net: PNET){.cdecl, dynlib: lib, importc: "net_clear".}
  256. proc net_realloc*(net: PNET, len: int): my_bool{.cdecl, dynlib: lib,
  257. importc: "net_realloc".}
  258. proc net_flush*(net: PNET): my_bool{.cdecl, dynlib: lib, importc: "net_flush".}
  259. proc my_net_write*(net: PNET, packet: cstring, length: int): my_bool{.cdecl,
  260. dynlib: lib, importc: "my_net_write".}
  261. proc net_write_command*(net: PNET, command: char, header: cstring,
  262. head_len: int, packet: cstring, length: int): my_bool{.
  263. cdecl, dynlib: lib, importc: "net_write_command".}
  264. proc net_real_write*(net: PNET, packet: cstring, length: int): cint{.cdecl,
  265. dynlib: lib, importc: "net_real_write".}
  266. proc my_net_read*(net: PNET): int{.cdecl, dynlib: lib, importc: "my_net_read".}
  267. # The following function is not meant for normal usage
  268. # Currently it's used internally by manager.c
  269. type
  270. Psockaddr* = ptr Sockaddr
  271. Sockaddr*{.final.} = object # undefined structure
  272. {.deprecated: [Tsockaddr: Sockaddr].}
  273. proc my_connect*(s: my_socket, name: Psockaddr, namelen: cuint, timeout: cuint): cint{.
  274. cdecl, dynlib: lib, importc: "my_connect".}
  275. type
  276. Prand_struct* = ptr Rand_struct
  277. Rand_struct*{.final.} = object # The following is for user defined functions
  278. seed1*: int
  279. seed2*: int
  280. max_value*: int
  281. max_value_dbl*: cdouble
  282. Item_result* = enum
  283. STRING_RESULT, REAL_RESULT, INT_RESULT, ROW_RESULT, DECIMAL_RESULT
  284. PItem_result* = ptr Item_result
  285. Pst_udf_args* = ptr St_udf_args
  286. St_udf_args*{.final.} = object
  287. arg_count*: cuint # Number of arguments
  288. arg_type*: PItem_result # Pointer to item_results
  289. args*: cstringArray # Pointer to item_results
  290. lengths*: ptr int # Length of string arguments
  291. maybe_null*: cstring # Length of string arguments
  292. attributes*: cstringArray # Pointer to attribute name
  293. attribute_lengths*: ptr int # Length of attribute arguments
  294. UDF_ARGS* = St_udf_args
  295. PUDF_ARGS* = ptr UDF_ARGS # This holds information about the result
  296. Pst_udf_init* = ptr St_udf_init
  297. St_udf_init*{.final.} = object
  298. maybe_null*: my_bool # 1 if function can return NULL
  299. decimals*: cuint # for real functions
  300. max_length*: int # For string functions
  301. theptr*: cstring # free pointer for function data
  302. const_item*: my_bool # free pointer for function data
  303. UDF_INIT* = St_udf_init
  304. PUDF_INIT* = ptr UDF_INIT # Constants when using compression
  305. {.deprecated: [Trand_stuct: Rand_struct, TItem_result: Item_result,
  306. Tst_udf_args: St_udf_args, TUDF_ARGS: UDF_ARGS,
  307. Tst_udf_init: St_udf_init, TUDF_INIT: UDF_INIT].}
  308. const
  309. NET_HEADER_SIZE* = 4 # standard header size
  310. COMP_HEADER_SIZE* = 3 # compression header extra size
  311. # Prototypes to password functions
  312. # These functions are used for authentication by client and server and
  313. # implemented in sql/password.c
  314. proc randominit*(para1: Prand_struct, seed1: int, seed2: int){.cdecl,
  315. dynlib: lib, importc: "randominit".}
  316. proc my_rnd*(para1: Prand_struct): cdouble{.cdecl, dynlib: lib,
  317. importc: "my_rnd".}
  318. proc create_random_string*(fto: cstring, len: cuint, rand_st: Prand_struct){.
  319. cdecl, dynlib: lib, importc: "create_random_string".}
  320. proc hash_password*(fto: int, password: cstring, password_len: cuint){.cdecl,
  321. dynlib: lib, importc: "hash_password".}
  322. proc make_scrambled_password_323*(fto: cstring, password: cstring){.cdecl,
  323. dynlib: lib, importc: "make_scrambled_password_323".}
  324. proc scramble_323*(fto: cstring, message: cstring, password: cstring){.cdecl,
  325. dynlib: lib, importc: "scramble_323".}
  326. proc check_scramble_323*(para1: cstring, message: cstring, salt: int): my_bool{.
  327. cdecl, dynlib: lib, importc: "check_scramble_323".}
  328. proc get_salt_from_password_323*(res: ptr int, password: cstring){.cdecl,
  329. dynlib: lib, importc: "get_salt_from_password_323".}
  330. proc make_password_from_salt_323*(fto: cstring, salt: ptr int){.cdecl,
  331. dynlib: lib, importc: "make_password_from_salt_323".}
  332. proc octet2hex*(fto: cstring, str: cstring, length: cuint): cstring{.cdecl,
  333. dynlib: lib, importc: "octet2hex".}
  334. proc make_scrambled_password*(fto: cstring, password: cstring){.cdecl,
  335. dynlib: lib, importc: "make_scrambled_password".}
  336. proc scramble*(fto: cstring, message: cstring, password: cstring){.cdecl,
  337. dynlib: lib, importc: "scramble".}
  338. proc check_scramble*(reply: cstring, message: cstring, hash_stage2: pointer): my_bool{.
  339. cdecl, dynlib: lib, importc: "check_scramble".}
  340. proc get_salt_from_password*(res: pointer, password: cstring){.cdecl,
  341. dynlib: lib, importc: "get_salt_from_password".}
  342. proc make_password_from_salt*(fto: cstring, hash_stage2: pointer){.cdecl,
  343. dynlib: lib, importc: "make_password_from_salt".}
  344. # end of password.c
  345. proc get_tty_password*(opt_message: cstring): cstring{.cdecl, dynlib: lib,
  346. importc: "get_tty_password".}
  347. proc errno_to_sqlstate*(errno: cuint): cstring{.cdecl, dynlib: lib,
  348. importc: "mysql_errno_to_sqlstate".}
  349. # Some other useful functions
  350. proc modify_defaults_file*(file_location: cstring, option: cstring,
  351. option_value: cstring, section_name: cstring,
  352. remove_option: cint): cint{.cdecl, dynlib: lib,
  353. importc: "load_defaults".}
  354. proc load_defaults*(conf_file: cstring, groups: cstringArray, argc: ptr cint,
  355. argv: ptr cstringArray): cint{.cdecl, dynlib: lib,
  356. importc: "load_defaults".}
  357. proc my_init*(): my_bool{.cdecl, dynlib: lib, importc: "my_init".}
  358. proc my_thread_init*(): my_bool{.cdecl, dynlib: lib, importc: "my_thread_init".}
  359. proc my_thread_end*(){.cdecl, dynlib: lib, importc: "my_thread_end".}
  360. const
  361. NULL_LENGTH*: int = int(not (0)) # For net_store_length
  362. const
  363. STMT_HEADER* = 4
  364. LONG_DATA_HEADER* = 6 # ------------ Stop of declaration in "mysql_com.h" -----------------------
  365. # $include "mysql_time.h"
  366. # $include "mysql_version.h"
  367. # $include "typelib.h"
  368. # $include "my_list.h" /* for LISTs used in 'MYSQL' and 'MYSQL_STMT' */
  369. # var
  370. # mysql_port : cuint;cvar;external;
  371. # mysql_unix_port : Pchar;cvar;external;
  372. const
  373. CLIENT_NET_READ_TIMEOUT* = 365 * 24 * 3600 # Timeout on read
  374. CLIENT_NET_WRITE_TIMEOUT* = 365 * 24 * 3600 # Timeout on write
  375. type
  376. Pst_mysql_field* = ptr St_mysql_field
  377. St_mysql_field*{.final.} = object
  378. name*: cstring # Name of column
  379. org_name*: cstring # Original column name, if an alias
  380. table*: cstring # Table of column if column was a field
  381. org_table*: cstring # Org table name, if table was an alias
  382. db*: cstring # Database for table
  383. catalog*: cstring # Catalog for table
  384. def*: cstring # Default value (set by mysql_list_fields)
  385. len*: int # Width of column (create length)
  386. max_length*: int # Max width for selected set
  387. name_length*: cuint
  388. org_name_length*: cuint
  389. table_length*: cuint
  390. org_table_length*: cuint
  391. db_length*: cuint
  392. catalog_length*: cuint
  393. def_length*: cuint
  394. flags*: cuint # Div flags
  395. decimals*: cuint # Number of decimals in field
  396. charsetnr*: cuint # Character set
  397. ftype*: Enum_field_types # Type of field. See mysql_com.h for types
  398. extension*: pointer
  399. FIELD* = St_mysql_field
  400. PFIELD* = ptr FIELD
  401. PROW* = ptr ROW # return data as array of strings
  402. ROW* = cstringArray
  403. PFIELD_OFFSET* = ptr FIELD_OFFSET # offset to current field
  404. FIELD_OFFSET* = cuint
  405. {.deprecated: [Tst_mysql_field: St_mysql_field, TFIELD: FIELD, TROW: ROW,
  406. TFIELD_OFFSET: FIELD_OFFSET].}
  407. proc IS_PRI_KEY*(n: int32): bool
  408. proc IS_NOT_NULL*(n: int32): bool
  409. proc IS_BLOB*(n: int32): bool
  410. proc IS_NUM*(t: Enum_field_types): bool
  411. proc INTERNAL_NUM_FIELD*(f: Pst_mysql_field): bool
  412. proc IS_NUM_FIELD*(f: Pst_mysql_field): bool
  413. type
  414. my_ulonglong* = int64
  415. Pmy_ulonglong* = ptr my_ulonglong
  416. const
  417. COUNT_ERROR* = not (my_ulonglong(0))
  418. type
  419. Pst_mysql_rows* = ptr St_mysql_rows
  420. St_mysql_rows*{.final.} = object
  421. next*: Pst_mysql_rows # list of rows
  422. data*: ROW
  423. len*: int
  424. ROWS* = St_mysql_rows
  425. PROWS* = ptr ROWS
  426. PROW_OFFSET* = ptr ROW_OFFSET # offset to current row
  427. ROW_OFFSET* = ROWS
  428. {.deprecated: [Tst_mysql_rows: St_mysql_rows, TROWS: ROWS,
  429. TROW_OFFSET: ROW_OFFSET].}
  430. const
  431. ALLOC_MAX_BLOCK_TO_DROP* = 4096
  432. ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP* = 10 # struct for once_alloc (block)
  433. type
  434. Pst_used_mem* = ptr St_used_mem
  435. St_used_mem*{.final.} = object
  436. next*: Pst_used_mem # Next block in use
  437. left*: cuint # memory left in block
  438. size*: cuint # size of block
  439. USED_MEM* = St_used_mem
  440. PUSED_MEM* = ptr USED_MEM
  441. Pst_mem_root* = ptr St_mem_root
  442. St_mem_root*{.final.} = object
  443. free*: PUSED_MEM # blocks with free memory in it
  444. used*: PUSED_MEM # blocks almost without free memory
  445. pre_alloc*: PUSED_MEM # preallocated block
  446. min_malloc*: cuint # if block have less memory it will be put in 'used' list
  447. block_size*: cuint # initial block size
  448. block_num*: cuint # allocated blocks counter
  449. # first free block in queue test counter (if it exceed
  450. # MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
  451. first_block_usage*: cuint
  452. error_handler*: proc (){.cdecl.}
  453. MEM_ROOT* = St_mem_root
  454. PMEM_ROOT* = ptr MEM_ROOT # ------------ Stop of declaration in "my_alloc.h" ----------------------
  455. {.deprecated: [Tst_used_mem: St_used_mem, TUSED_MEM: USED_MEM,
  456. Tst_mem_root: St_mem_root, TMEM_ROOT: MEM_ROOT].}
  457. type
  458. Pst_mysql_data* = ptr St_mysql_data
  459. St_mysql_data*{.final.} = object
  460. rows*: my_ulonglong
  461. fields*: cuint
  462. data*: PROWS
  463. alloc*: MEM_ROOT
  464. prev_ptr*: ptr PROWS
  465. DATA* = St_mysql_data
  466. PDATA* = ptr DATA
  467. Option* = enum
  468. OPT_CONNECT_TIMEOUT, OPT_COMPRESS, OPT_NAMED_PIPE, INIT_COMMAND,
  469. READ_DEFAULT_FILE, READ_DEFAULT_GROUP, SET_CHARSET_DIR, SET_CHARSET_NAME,
  470. OPT_LOCAL_INFILE, OPT_PROTOCOL, SHARED_MEMORY_BASE_NAME, OPT_READ_TIMEOUT,
  471. OPT_WRITE_TIMEOUT, OPT_USE_RESULT, OPT_USE_REMOTE_CONNECTION,
  472. OPT_USE_EMBEDDED_CONNECTION, OPT_GUESS_CONNECTION, SET_CLIENT_IP,
  473. SECURE_AUTH, REPORT_DATA_TRUNCATION, OPT_RECONNECT
  474. {.deprecated: [Tst_mysql_data: St_mysql_data, TDATA: DATA, Toption: Option].}
  475. const
  476. MAX_MYSQL_MANAGER_ERR* = 256
  477. MAX_MYSQL_MANAGER_MSG* = 256
  478. MANAGER_OK* = 200
  479. MANAGER_INFO* = 250
  480. MANAGER_ACCESS* = 401
  481. MANAGER_CLIENT_ERR* = 450
  482. MANAGER_INTERNAL_ERR* = 500
  483. type
  484. St_dynamic_array*{.final.} = object
  485. buffer*: cstring
  486. elements*: cuint
  487. max_element*: cuint
  488. alloc_increment*: cuint
  489. size_of_element*: cuint
  490. DYNAMIC_ARRAY* = St_dynamic_array
  491. Pst_dynamic_array* = ptr St_dynamic_array
  492. Pst_mysql_options* = ptr St_mysql_options
  493. St_mysql_options*{.final.} = object
  494. connect_timeout*: cuint
  495. read_timeout*: cuint
  496. write_timeout*: cuint
  497. port*: cuint
  498. protocol*: cuint
  499. client_flag*: int
  500. host*: cstring
  501. user*: cstring
  502. password*: cstring
  503. unix_socket*: cstring
  504. db*: cstring
  505. init_commands*: Pst_dynamic_array
  506. my_cnf_file*: cstring
  507. my_cnf_group*: cstring
  508. charset_dir*: cstring
  509. charset_name*: cstring
  510. ssl_key*: cstring # PEM key file
  511. ssl_cert*: cstring # PEM cert file
  512. ssl_ca*: cstring # PEM CA file
  513. ssl_capath*: cstring # PEM directory of CA-s?
  514. ssl_cipher*: cstring # cipher to use
  515. shared_memory_base_name*: cstring
  516. max_allowed_packet*: int
  517. use_ssl*: my_bool # if to use SSL or not
  518. compress*: my_bool
  519. named_pipe*: my_bool # On connect, find out the replication role of the server, and
  520. # establish connections to all the peers
  521. rpl_probe*: my_bool # Each call to mysql_real_query() will parse it to tell if it is a read
  522. # or a write, and direct it to the slave or the master
  523. rpl_parse*: my_bool # If set, never read from a master, only from slave, when doing
  524. # a read that is replication-aware
  525. no_master_reads*: my_bool
  526. separate_thread*: my_bool
  527. methods_to_use*: Option
  528. client_ip*: cstring
  529. secure_auth*: my_bool # Refuse client connecting to server if it uses old (pre-4.1.1) protocol
  530. report_data_truncation*: my_bool # 0 - never report, 1 - always report (default)
  531. # function pointers for local infile support
  532. local_infile_init*: proc (para1: var pointer, para2: cstring, para3: pointer): cint{.
  533. cdecl.}
  534. local_infile_read*: proc (para1: pointer, para2: cstring, para3: cuint): cint
  535. local_infile_end*: proc (para1: pointer)
  536. local_infile_error*: proc (para1: pointer, para2: cstring, para3: cuint): cint
  537. local_infile_userdata*: pointer
  538. Status* = enum
  539. STATUS_READY, STATUS_GET_RESULT, STATUS_USE_RESULT
  540. Protocol_type* = enum # There are three types of queries - the ones that have to go to
  541. # the master, the ones that go to a slave, and the administrative
  542. # type which must happen on the pivot connection
  543. PROTOCOL_DEFAULT, PROTOCOL_TCP, PROTOCOL_SOCKET, PROTOCOL_PIPE,
  544. PROTOCOL_MEMORY
  545. Rpl_type* = enum
  546. RPL_MASTER, RPL_SLAVE, RPL_ADMIN
  547. Charset_info_st*{.final.} = object
  548. number*: cuint
  549. primary_number*: cuint
  550. binary_number*: cuint
  551. state*: cuint
  552. csname*: cstring
  553. name*: cstring
  554. comment*: cstring
  555. tailoring*: cstring
  556. ftype*: cstring
  557. to_lower*: cstring
  558. to_upper*: cstring
  559. sort_order*: cstring
  560. contractions*: ptr int16
  561. sort_order_big*: ptr ptr int16
  562. tab_to_uni*: ptr int16
  563. tab_from_uni*: pointer # was ^MY_UNI_IDX
  564. state_map*: cstring
  565. ident_map*: cstring
  566. strxfrm_multiply*: cuint
  567. mbminlen*: cuint
  568. mbmaxlen*: cuint
  569. min_sort_char*: int16
  570. max_sort_char*: int16
  571. escape_with_backslash_is_dangerous*: my_bool
  572. cset*: pointer # was ^MY_CHARSET_HANDLER
  573. coll*: pointer # was ^MY_COLLATION_HANDLER;
  574. CHARSET_INFO* = Charset_info_st
  575. Pcharset_info_st* = ptr Charset_info_st
  576. Pcharacter_set* = ptr Character_set
  577. Character_set*{.final.} = object
  578. number*: cuint
  579. state*: cuint
  580. csname*: cstring
  581. name*: cstring
  582. comment*: cstring
  583. dir*: cstring
  584. mbminlen*: cuint
  585. mbmaxlen*: cuint
  586. MY_CHARSET_INFO* = Character_set
  587. PMY_CHARSET_INFO* = ptr MY_CHARSET_INFO
  588. Pst_mysql_methods* = ptr St_mysql_methods
  589. Pst_mysql* = ptr St_mysql
  590. St_mysql*{.final.} = object
  591. net*: NET # Communication parameters
  592. connector_fd*: gptr # ConnectorFd for SSL
  593. host*: cstring
  594. user*: cstring
  595. passwd*: cstring
  596. unix_socket*: cstring
  597. server_version*: cstring
  598. host_info*: cstring
  599. info*: cstring
  600. db*: cstring
  601. charset*: Pcharset_info_st
  602. fields*: PFIELD
  603. field_alloc*: MEM_ROOT
  604. affected_rows*: my_ulonglong
  605. insert_id*: my_ulonglong # id if insert on table with NEXTNR
  606. extra_info*: my_ulonglong # Used by mysqlshow, not used by mysql 5.0 and up
  607. thread_id*: int # Id for connection in server
  608. packet_length*: int
  609. port*: cuint
  610. client_flag*: int
  611. server_capabilities*: int
  612. protocol_version*: cuint
  613. field_count*: cuint
  614. server_status*: cuint
  615. server_language*: cuint
  616. warning_count*: cuint
  617. options*: St_mysql_options
  618. status*: Status
  619. free_me*: my_bool # If free in mysql_close
  620. reconnect*: my_bool # set to 1 if automatic reconnect
  621. scramble*: array[0..(SCRAMBLE_LENGTH + 1) - 1, char] # session-wide random string
  622. # Set if this is the original connection, not a master or a slave we have
  623. # added though mysql_rpl_probe() or mysql_set_master()/ mysql_add_slave()
  624. rpl_pivot*: my_bool # Pointers to the master, and the next slave connections, points to
  625. # itself if lone connection.
  626. master*: Pst_mysql
  627. next_slave*: Pst_mysql
  628. last_used_slave*: Pst_mysql # needed for round-robin slave pick
  629. last_used_con*: Pst_mysql # needed for send/read/store/use result to work correctly with replication
  630. stmts*: pointer # was PList, list of all statements
  631. methods*: Pst_mysql_methods
  632. thd*: pointer # Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag
  633. # from mysql_stmt_close if close had to cancel result set of this object.
  634. unbuffered_fetch_owner*: Pmy_bool
  635. MySQL* = St_mysql
  636. PMySQL* = ptr MySQL
  637. Pst_mysql_res* = ptr St_mysql_res
  638. St_mysql_res*{.final.} = object
  639. row_count*: my_ulonglong
  640. fields*: PFIELD
  641. data*: PDATA
  642. data_cursor*: PROWS
  643. lengths*: ptr int # column lengths of current row
  644. handle*: PMySQL # for unbuffered reads
  645. field_alloc*: MEM_ROOT
  646. field_count*: cuint
  647. current_field*: cuint
  648. row*: ROW # If unbuffered read
  649. current_row*: ROW # buffer to current row
  650. eof*: my_bool # Used by mysql_fetch_row
  651. unbuffered_fetch_cancelled*: my_bool # mysql_stmt_close() had to cancel this result
  652. methods*: Pst_mysql_methods
  653. RES* = St_mysql_res
  654. PRES* = ptr RES
  655. Pst_mysql_stmt* = ptr St_mysql_stmt
  656. PSTMT* = ptr STMT
  657. St_mysql_methods*{.final.} = object
  658. read_query_result*: proc (MySQL: PMySQL): my_bool{.cdecl.}
  659. advanced_command*: proc (MySQL: PMySQL, command: Enum_server_command, header: cstring,
  660. header_length: int, arg: cstring, arg_length: int,
  661. skip_check: my_bool): my_bool
  662. read_rows*: proc (MySQL: PMySQL, fields: PFIELD, fields_count: cuint): PDATA
  663. use_result*: proc (MySQL: PMySQL): PRES
  664. fetch_lengths*: proc (fto: ptr int, column: ROW, field_count: cuint)
  665. flush_use_result*: proc (MySQL: PMySQL)
  666. list_fields*: proc (MySQL: PMySQL): PFIELD
  667. read_prepare_result*: proc (MySQL: PMySQL, stmt: PSTMT): my_bool
  668. stmt_execute*: proc (stmt: PSTMT): cint
  669. read_binary_rows*: proc (stmt: PSTMT): cint
  670. unbuffered_fetch*: proc (MySQL: PMySQL, row: cstringArray): cint
  671. free_embedded_thd*: proc (MySQL: PMySQL)
  672. read_statistics*: proc (MySQL: PMySQL): cstring
  673. next_result*: proc (MySQL: PMySQL): my_bool
  674. read_change_user_result*: proc (MySQL: PMySQL, buff: cstring, passwd: cstring): cint
  675. read_rowsfrom_cursor*: proc (stmt: PSTMT): cint
  676. METHODS* = St_mysql_methods
  677. PMETHODS* = ptr METHODS
  678. Pst_mysql_manager* = ptr St_mysql_manager
  679. St_mysql_manager*{.final.} = object
  680. net*: NET
  681. host*: cstring
  682. user*: cstring
  683. passwd*: cstring
  684. port*: cuint
  685. free_me*: my_bool
  686. eof*: my_bool
  687. cmd_status*: cint
  688. last_errno*: cint
  689. net_buf*: cstring
  690. net_buf_pos*: cstring
  691. net_data_end*: cstring
  692. net_buf_size*: cint
  693. last_error*: array[0..(MAX_MYSQL_MANAGER_ERR) - 1, char]
  694. MANAGER* = St_mysql_manager
  695. PMANAGER* = ptr MANAGER
  696. Pst_mysql_parameters* = ptr St_mysql_parameters
  697. St_mysql_parameters*{.final.} = object
  698. p_max_allowed_packet*: ptr int
  699. p_net_buffer_length*: ptr int
  700. PARAMETERS* = St_mysql_parameters
  701. PPARAMETERS* = ptr PARAMETERS
  702. Enum_mysql_stmt_state* = enum
  703. STMT_INIT_DONE = 1, STMT_PREPARE_DONE, STMT_EXECUTE_DONE, STMT_FETCH_DONE
  704. Pst_mysql_bind* = ptr St_mysql_bind
  705. St_mysql_bind*{.final.} = object
  706. len*: int # output length pointer
  707. is_null*: Pmy_bool # Pointer to null indicator
  708. buffer*: pointer # buffer to get/put data
  709. error*: Pmy_bool # set this if you want to track data truncations happened during fetch
  710. buffer_type*: Enum_field_types # buffer type
  711. buffer_length*: int # buffer length, must be set for str/binary
  712. # Following are for internal use. Set by mysql_stmt_bind_param
  713. row_ptr*: ptr byte # for the current data position
  714. offset*: int # offset position for char/binary fetch
  715. length_value*: int # Used if length is 0
  716. param_number*: cuint # For null count and error messages
  717. pack_length*: cuint # Internal length for packed data
  718. error_value*: my_bool # used if error is 0
  719. is_unsigned*: my_bool # set if integer type is unsigned
  720. long_data_used*: my_bool # If used with mysql_send_long_data
  721. is_null_value*: my_bool # Used if is_null is 0
  722. store_param_func*: proc (net: PNET, param: Pst_mysql_bind){.cdecl.}
  723. fetch_result*: proc (para1: Pst_mysql_bind, para2: PFIELD, row: PPByte)
  724. skip_result*: proc (para1: Pst_mysql_bind, para2: PFIELD, row: PPByte)
  725. BIND* = St_mysql_bind
  726. PBIND* = ptr BIND # statement handler
  727. St_mysql_stmt*{.final.} = object
  728. mem_root*: MEM_ROOT # root allocations
  729. mysql*: PMySQL # connection handle
  730. params*: PBIND # input parameters
  731. `bind`*: PBIND # input parameters
  732. fields*: PFIELD # result set metadata
  733. result*: DATA # cached result set
  734. data_cursor*: PROWS # current row in cached result
  735. affected_rows*: my_ulonglong # copy of mysql->affected_rows after statement execution
  736. insert_id*: my_ulonglong
  737. read_row_func*: proc (stmt: Pst_mysql_stmt, row: PPByte): cint{.cdecl.}
  738. stmt_id*: int # Id for prepared statement
  739. flags*: int # i.e. type of cursor to open
  740. prefetch_rows*: int # number of rows per one COM_FETCH
  741. server_status*: cuint # Copied from mysql->server_status after execute/fetch to know
  742. # server-side cursor status for this statement.
  743. last_errno*: cuint # error code
  744. param_count*: cuint # input parameter count
  745. field_count*: cuint # number of columns in result set
  746. state*: Enum_mysql_stmt_state # statement state
  747. last_error*: array[0..(ERRMSG_SIZE) - 1, char] # error message
  748. sqlstate*: array[0..(SQLSTATE_LENGTH + 1) - 1, char]
  749. send_types_to_server*: my_bool # Types of input parameters should be sent to server
  750. bind_param_done*: my_bool # input buffers were supplied
  751. bind_result_done*: char # output buffers were supplied
  752. unbuffered_fetch_cancelled*: my_bool
  753. update_max_length*: my_bool
  754. STMT* = St_mysql_stmt
  755. Enum_stmt_attr_type* = enum
  756. STMT_ATTR_UPDATE_MAX_LENGTH, STMT_ATTR_CURSOR_TYPE, STMT_ATTR_PREFETCH_ROWS
  757. {.deprecated: [Tst_dynamic_array: St_dynamic_array, Tst_mysql_options: St_mysql_options,
  758. TDYNAMIC_ARRAY: DYNAMIC_ARRAY, Tprotocol_type: Protocol_type,
  759. Trpl_type: Rpl_type, Tcharset_info_st: Charset_info_st,
  760. TCHARSET_INFO: CHARSET_INFO, Tcharacter_set: Character_set,
  761. TMY_CHARSET_INFO: MY_CHARSET_INFO, Tst_mysql: St_mysql,
  762. Tst_mysql_methods: St_mysql_methods, TMySql: MySql,
  763. Tst_mysql_res: St_mysql_res, TMETHODS: METHODS, TRES: RES,
  764. Tst_mysql_manager: St_mysql_manager, TMANAGER: MANAGER,
  765. Tst_mysql_parameters: St_mysql_parameters, TPARAMETERS: PARAMETERS,
  766. Tenum_mysql_stmt_state: Enum_mysql_stmt_state,
  767. Tst_mysql_bind: St_mysql_bind, TBIND: BIND, Tst_mysql_stmt: St_mysql_stmt,
  768. TSTMT: STMT, Tenum_stmt_attr_type: Enum_stmt_attr_type,
  769. Tstatus: Status].}
  770. proc server_init*(argc: cint, argv: cstringArray, groups: cstringArray): cint{.
  771. cdecl, dynlib: lib, importc: "mysql_server_init".}
  772. proc server_end*(){.cdecl, dynlib: lib, importc: "mysql_server_end".}
  773. # mysql_server_init/end need to be called when using libmysqld or
  774. # libmysqlclient (exactly, mysql_server_init() is called by mysql_init() so
  775. # you don't need to call it explicitly; but you need to call
  776. # mysql_server_end() to free memory). The names are a bit misleading
  777. # (mysql_SERVER* to be used when using libmysqlCLIENT). So we add more general
  778. # names which suit well whether you're using libmysqld or libmysqlclient. We
  779. # intend to promote these aliases over the mysql_server* ones.
  780. proc library_init*(argc: cint, argv: cstringArray, groups: cstringArray): cint{.
  781. cdecl, dynlib: lib, importc: "mysql_server_init".}
  782. proc library_end*(){.cdecl, dynlib: lib, importc: "mysql_server_end".}
  783. proc get_parameters*(): PPARAMETERS{.stdcall, dynlib: lib,
  784. importc: "mysql_get_parameters".}
  785. # Set up and bring down a thread; these function should be called
  786. # for each thread in an application which opens at least one MySQL
  787. # connection. All uses of the connection(s) should be between these
  788. # function calls.
  789. proc thread_init*(): my_bool{.stdcall, dynlib: lib, importc: "mysql_thread_init".}
  790. proc thread_end*(){.stdcall, dynlib: lib, importc: "mysql_thread_end".}
  791. # Functions to get information from the MYSQL and MYSQL_RES structures
  792. # Should definitely be used if one uses shared libraries.
  793. proc num_rows*(res: PRES): my_ulonglong{.stdcall, dynlib: lib,
  794. importc: "mysql_num_rows".}
  795. proc num_fields*(res: PRES): cuint{.stdcall, dynlib: lib,
  796. importc: "mysql_num_fields".}
  797. proc eof*(res: PRES): my_bool{.stdcall, dynlib: lib, importc: "mysql_eof".}
  798. proc fetch_field_direct*(res: PRES, fieldnr: cuint): PFIELD{.stdcall,
  799. dynlib: lib, importc: "mysql_fetch_field_direct".}
  800. proc fetch_fields*(res: PRES): PFIELD{.stdcall, dynlib: lib,
  801. importc: "mysql_fetch_fields".}
  802. proc row_tell*(res: PRES): ROW_OFFSET{.stdcall, dynlib: lib,
  803. importc: "mysql_row_tell".}
  804. proc field_tell*(res: PRES): FIELD_OFFSET{.stdcall, dynlib: lib,
  805. importc: "mysql_field_tell".}
  806. proc field_count*(MySQL: PMySQL): cuint{.stdcall, dynlib: lib,
  807. importc: "mysql_field_count".}
  808. proc affected_rows*(MySQL: PMySQL): my_ulonglong{.stdcall, dynlib: lib,
  809. importc: "mysql_affected_rows".}
  810. proc insert_id*(MySQL: PMySQL): my_ulonglong{.stdcall, dynlib: lib,
  811. importc: "mysql_insert_id".}
  812. proc errno*(MySQL: PMySQL): cuint{.stdcall, dynlib: lib, importc: "mysql_errno".}
  813. proc error*(MySQL: PMySQL): cstring{.stdcall, dynlib: lib, importc: "mysql_error".}
  814. proc sqlstate*(MySQL: PMySQL): cstring{.stdcall, dynlib: lib, importc: "mysql_sqlstate".}
  815. proc warning_count*(MySQL: PMySQL): cuint{.stdcall, dynlib: lib,
  816. importc: "mysql_warning_count".}
  817. proc info*(MySQL: PMySQL): cstring{.stdcall, dynlib: lib, importc: "mysql_info".}
  818. proc thread_id*(MySQL: PMySQL): int{.stdcall, dynlib: lib, importc: "mysql_thread_id".}
  819. proc character_set_name*(MySQL: PMySQL): cstring{.stdcall, dynlib: lib,
  820. importc: "mysql_character_set_name".}
  821. proc set_character_set*(MySQL: PMySQL, csname: cstring): int32{.stdcall, dynlib: lib,
  822. importc: "mysql_set_character_set".}
  823. proc init*(MySQL: PMySQL): PMySQL{.stdcall, dynlib: lib, importc: "mysql_init".}
  824. proc ssl_set*(MySQL: PMySQL, key: cstring, cert: cstring, ca: cstring, capath: cstring,
  825. cipher: cstring): my_bool{.stdcall, dynlib: lib,
  826. importc: "mysql_ssl_set".}
  827. proc change_user*(MySQL: PMySQL, user: cstring, passwd: cstring, db: cstring): my_bool{.
  828. stdcall, dynlib: lib, importc: "mysql_change_user".}
  829. proc real_connect*(MySQL: PMySQL, host: cstring, user: cstring, passwd: cstring,
  830. db: cstring, port: cuint, unix_socket: cstring,
  831. clientflag: int): PMySQL{.stdcall, dynlib: lib,
  832. importc: "mysql_real_connect".}
  833. proc select_db*(MySQL: PMySQL, db: cstring): cint{.stdcall, dynlib: lib,
  834. importc: "mysql_select_db".}
  835. proc query*(MySQL: PMySQL, q: cstring): cint{.stdcall, dynlib: lib, importc: "mysql_query".}
  836. proc send_query*(MySQL: PMySQL, q: cstring, len: int): cint{.stdcall, dynlib: lib,
  837. importc: "mysql_send_query".}
  838. proc real_query*(MySQL: PMySQL, q: cstring, len: int): cint{.stdcall, dynlib: lib,
  839. importc: "mysql_real_query".}
  840. proc store_result*(MySQL: PMySQL): PRES{.stdcall, dynlib: lib,
  841. importc: "mysql_store_result".}
  842. proc use_result*(MySQL: PMySQL): PRES{.stdcall, dynlib: lib, importc: "mysql_use_result".}
  843. # perform query on master
  844. proc master_query*(MySQL: PMySQL, q: cstring, len: int): my_bool{.stdcall, dynlib: lib,
  845. importc: "mysql_master_query".}
  846. proc master_send_query*(MySQL: PMySQL, q: cstring, len: int): my_bool{.stdcall,
  847. dynlib: lib, importc: "mysql_master_send_query".}
  848. # perform query on slave
  849. proc slave_query*(MySQL: PMySQL, q: cstring, len: int): my_bool{.stdcall, dynlib: lib,
  850. importc: "mysql_slave_query".}
  851. proc slave_send_query*(MySQL: PMySQL, q: cstring, len: int): my_bool{.stdcall,
  852. dynlib: lib, importc: "mysql_slave_send_query".}
  853. proc get_character_set_info*(MySQL: PMySQL, charset: PMY_CHARSET_INFO){.stdcall,
  854. dynlib: lib, importc: "mysql_get_character_set_info".}
  855. # local infile support
  856. const
  857. LOCAL_INFILE_ERROR_LEN* = 512
  858. # procedure mysql_set_local_infile_handler(mysql:PMYSQL; local_infile_init:function (para1:Ppointer; para2:Pchar; para3:pointer):longint; local_infile_read:function (para1:pointer; para2:Pchar; para3:dword):longint; local_infile_end:procedure (_pa
  859. # para6:pointer);cdecl;external mysqllib name 'mysql_set_local_infile_handler';
  860. proc set_local_infile_default*(MySQL: PMySQL){.cdecl, dynlib: lib,
  861. importc: "mysql_set_local_infile_default".}
  862. # enable/disable parsing of all queries to decide if they go on master or
  863. # slave
  864. proc enable_rpl_parse*(MySQL: PMySQL){.stdcall, dynlib: lib,
  865. importc: "mysql_enable_rpl_parse".}
  866. proc disable_rpl_parse*(MySQL: PMySQL){.stdcall, dynlib: lib,
  867. importc: "mysql_disable_rpl_parse".}
  868. # get the value of the parse flag
  869. proc rpl_parse_enabled*(MySQL: PMySQL): cint{.stdcall, dynlib: lib,
  870. importc: "mysql_rpl_parse_enabled".}
  871. # enable/disable reads from master
  872. proc enable_reads_from_master*(MySQL: PMySQL){.stdcall, dynlib: lib,
  873. importc: "mysql_enable_reads_from_master".}
  874. proc disable_reads_from_master*(MySQL: PMySQL){.stdcall, dynlib: lib, importc: "mysql_disable_reads_from_master".}
  875. # get the value of the master read flag
  876. proc reads_from_master_enabled*(MySQL: PMySQL): my_bool{.stdcall, dynlib: lib,
  877. importc: "mysql_reads_from_master_enabled".}
  878. proc rpl_query_type*(q: cstring, length: cint): Rpl_type{.stdcall, dynlib: lib,
  879. importc: "mysql_rpl_query_type".}
  880. # discover the master and its slaves
  881. proc rpl_probe*(MySQL: PMySQL): my_bool{.stdcall, dynlib: lib, importc: "mysql_rpl_probe".}
  882. # set the master, close/free the old one, if it is not a pivot
  883. proc set_master*(MySQL: PMySQL, host: cstring, port: cuint, user: cstring, passwd: cstring): cint{.
  884. stdcall, dynlib: lib, importc: "mysql_set_master".}
  885. proc add_slave*(MySQL: PMySQL, host: cstring, port: cuint, user: cstring, passwd: cstring): cint{.
  886. stdcall, dynlib: lib, importc: "mysql_add_slave".}
  887. proc shutdown*(MySQL: PMySQL, shutdown_level: Enum_shutdown_level): cint{.stdcall,
  888. dynlib: lib, importc: "mysql_shutdown".}
  889. proc dump_debug_info*(MySQL: PMySQL): cint{.stdcall, dynlib: lib,
  890. importc: "mysql_dump_debug_info".}
  891. proc refresh*(sql: PMySQL, refresh_options: cuint): cint{.stdcall, dynlib: lib,
  892. importc: "mysql_refresh".}
  893. proc kill*(MySQL: PMySQL, pid: int): cint{.stdcall, dynlib: lib, importc: "mysql_kill".}
  894. proc set_server_option*(MySQL: PMySQL, option: Enum_mysql_set_option): cint{.stdcall,
  895. dynlib: lib, importc: "mysql_set_server_option".}
  896. proc ping*(MySQL: PMySQL): cint{.stdcall, dynlib: lib, importc: "mysql_ping".}
  897. proc stat*(MySQL: PMySQL): cstring{.stdcall, dynlib: lib, importc: "mysql_stat".}
  898. proc get_server_info*(MySQL: PMySQL): cstring{.stdcall, dynlib: lib,
  899. importc: "mysql_get_server_info".}
  900. proc get_client_info*(): cstring{.stdcall, dynlib: lib,
  901. importc: "mysql_get_client_info".}
  902. proc get_client_version*(): int{.stdcall, dynlib: lib,
  903. importc: "mysql_get_client_version".}
  904. proc get_host_info*(MySQL: PMySQL): cstring{.stdcall, dynlib: lib,
  905. importc: "mysql_get_host_info".}
  906. proc get_server_version*(MySQL: PMySQL): int{.stdcall, dynlib: lib,
  907. importc: "mysql_get_server_version".}
  908. proc get_proto_info*(MySQL: PMySQL): cuint{.stdcall, dynlib: lib,
  909. importc: "mysql_get_proto_info".}
  910. proc list_dbs*(MySQL: PMySQL, wild: cstring): PRES{.stdcall, dynlib: lib,
  911. importc: "mysql_list_dbs".}
  912. proc list_tables*(MySQL: PMySQL, wild: cstring): PRES{.stdcall, dynlib: lib,
  913. importc: "mysql_list_tables".}
  914. proc list_processes*(MySQL: PMySQL): PRES{.stdcall, dynlib: lib,
  915. importc: "mysql_list_processes".}
  916. proc options*(MySQL: PMySQL, option: Option, arg: cstring): cint{.stdcall, dynlib: lib,
  917. importc: "mysql_options".}
  918. proc free_result*(result: PRES){.stdcall, dynlib: lib,
  919. importc: "mysql_free_result".}
  920. proc data_seek*(result: PRES, offset: my_ulonglong){.stdcall, dynlib: lib,
  921. importc: "mysql_data_seek".}
  922. proc row_seek*(result: PRES, offset: ROW_OFFSET): ROW_OFFSET{.stdcall,
  923. dynlib: lib, importc: "mysql_row_seek".}
  924. proc field_seek*(result: PRES, offset: FIELD_OFFSET): FIELD_OFFSET{.stdcall,
  925. dynlib: lib, importc: "mysql_field_seek".}
  926. proc fetch_row*(result: PRES): ROW{.stdcall, dynlib: lib,
  927. importc: "mysql_fetch_row".}
  928. proc fetch_lengths*(result: PRES): ptr int{.stdcall, dynlib: lib,
  929. importc: "mysql_fetch_lengths".}
  930. proc fetch_field*(result: PRES): PFIELD{.stdcall, dynlib: lib,
  931. importc: "mysql_fetch_field".}
  932. proc list_fields*(MySQL: PMySQL, table: cstring, wild: cstring): PRES{.stdcall,
  933. dynlib: lib, importc: "mysql_list_fields".}
  934. proc escape_string*(fto: cstring, `from`: cstring, from_length: int): int{.
  935. stdcall, dynlib: lib, importc: "mysql_escape_string".}
  936. proc hex_string*(fto: cstring, `from`: cstring, from_length: int): int{.stdcall,
  937. dynlib: lib, importc: "mysql_hex_string".}
  938. proc real_escape_string*(MySQL: PMySQL, fto: cstring, `from`: cstring, len: int): int{.
  939. stdcall, dynlib: lib, importc: "mysql_real_escape_string".}
  940. proc debug*(debug: cstring){.stdcall, dynlib: lib, importc: "mysql_debug".}
  941. # function mysql_odbc_escape_string(mysql:PMYSQL; fto:Pchar; to_length:dword; from:Pchar; from_length:dword;
  942. # param:pointer; extend_buffer:function (para1:pointer; to:Pchar; length:Pdword):Pchar):Pchar;stdcall;external mysqllib name 'mysql_odbc_escape_string';
  943. proc myodbc_remove_escape*(MySQL: PMySQL, name: cstring){.stdcall, dynlib: lib,
  944. importc: "myodbc_remove_escape".}
  945. proc thread_safe*(): cuint{.stdcall, dynlib: lib, importc: "mysql_thread_safe".}
  946. proc embedded*(): my_bool{.stdcall, dynlib: lib, importc: "mysql_embedded".}
  947. proc manager_init*(con: PMANAGER): PMANAGER{.stdcall, dynlib: lib,
  948. importc: "mysql_manager_init".}
  949. proc manager_connect*(con: PMANAGER, host: cstring, user: cstring,
  950. passwd: cstring, port: cuint): PMANAGER{.stdcall,
  951. dynlib: lib, importc: "mysql_manager_connect".}
  952. proc manager_close*(con: PMANAGER){.stdcall, dynlib: lib,
  953. importc: "mysql_manager_close".}
  954. proc manager_command*(con: PMANAGER, cmd: cstring, cmd_len: cint): cint{.
  955. stdcall, dynlib: lib, importc: "mysql_manager_command".}
  956. proc manager_fetch_line*(con: PMANAGER, res_buf: cstring, res_buf_size: cint): cint{.
  957. stdcall, dynlib: lib, importc: "mysql_manager_fetch_line".}
  958. proc read_query_result*(MySQL: PMySQL): my_bool{.stdcall, dynlib: lib,
  959. importc: "mysql_read_query_result".}
  960. proc stmt_init*(MySQL: PMySQL): PSTMT{.stdcall, dynlib: lib, importc: "mysql_stmt_init".}
  961. proc stmt_prepare*(stmt: PSTMT, query: cstring, len: int): cint{.stdcall,
  962. dynlib: lib, importc: "mysql_stmt_prepare".}
  963. proc stmt_execute*(stmt: PSTMT): cint{.stdcall, dynlib: lib,
  964. importc: "mysql_stmt_execute".}
  965. proc stmt_fetch*(stmt: PSTMT): cint{.stdcall, dynlib: lib,
  966. importc: "mysql_stmt_fetch".}
  967. proc stmt_fetch_column*(stmt: PSTMT, `bind`: PBIND, column: cuint, offset: int): cint{.
  968. stdcall, dynlib: lib, importc: "mysql_stmt_fetch_column".}
  969. proc stmt_store_result*(stmt: PSTMT): cint{.stdcall, dynlib: lib,
  970. importc: "mysql_stmt_store_result".}
  971. proc stmt_param_count*(stmt: PSTMT): int{.stdcall, dynlib: lib,
  972. importc: "mysql_stmt_param_count".}
  973. proc stmt_attr_set*(stmt: PSTMT, attr_type: Enum_stmt_attr_type, attr: pointer): my_bool{.
  974. stdcall, dynlib: lib, importc: "mysql_stmt_attr_set".}
  975. proc stmt_attr_get*(stmt: PSTMT, attr_type: Enum_stmt_attr_type, attr: pointer): my_bool{.
  976. stdcall, dynlib: lib, importc: "mysql_stmt_attr_get".}
  977. proc stmt_bind_param*(stmt: PSTMT, bnd: PBIND): my_bool{.stdcall, dynlib: lib,
  978. importc: "mysql_stmt_bind_param".}
  979. proc stmt_bind_result*(stmt: PSTMT, bnd: PBIND): my_bool{.stdcall, dynlib: lib,
  980. importc: "mysql_stmt_bind_result".}
  981. proc stmt_close*(stmt: PSTMT): my_bool{.stdcall, dynlib: lib,
  982. importc: "mysql_stmt_close".}
  983. proc stmt_reset*(stmt: PSTMT): my_bool{.stdcall, dynlib: lib,
  984. importc: "mysql_stmt_reset".}
  985. proc stmt_free_result*(stmt: PSTMT): my_bool{.stdcall, dynlib: lib,
  986. importc: "mysql_stmt_free_result".}
  987. proc stmt_send_long_data*(stmt: PSTMT, param_number: cuint, data: cstring,
  988. len: int): my_bool{.stdcall, dynlib: lib,
  989. importc: "mysql_stmt_send_long_data".}
  990. proc stmt_result_metadata*(stmt: PSTMT): PRES{.stdcall, dynlib: lib,
  991. importc: "mysql_stmt_result_metadata".}
  992. proc stmt_param_metadata*(stmt: PSTMT): PRES{.stdcall, dynlib: lib,
  993. importc: "mysql_stmt_param_metadata".}
  994. proc stmt_errno*(stmt: PSTMT): cuint{.stdcall, dynlib: lib,
  995. importc: "mysql_stmt_errno".}
  996. proc stmt_error*(stmt: PSTMT): cstring{.stdcall, dynlib: lib,
  997. importc: "mysql_stmt_error".}
  998. proc stmt_sqlstate*(stmt: PSTMT): cstring{.stdcall, dynlib: lib,
  999. importc: "mysql_stmt_sqlstate".}
  1000. proc stmt_row_seek*(stmt: PSTMT, offset: ROW_OFFSET): ROW_OFFSET{.stdcall,
  1001. dynlib: lib, importc: "mysql_stmt_row_seek".}
  1002. proc stmt_row_tell*(stmt: PSTMT): ROW_OFFSET{.stdcall, dynlib: lib,
  1003. importc: "mysql_stmt_row_tell".}
  1004. proc stmt_data_seek*(stmt: PSTMT, offset: my_ulonglong){.stdcall, dynlib: lib,
  1005. importc: "mysql_stmt_data_seek".}
  1006. proc stmt_num_rows*(stmt: PSTMT): my_ulonglong{.stdcall, dynlib: lib,
  1007. importc: "mysql_stmt_num_rows".}
  1008. proc stmt_affected_rows*(stmt: PSTMT): my_ulonglong{.stdcall, dynlib: lib,
  1009. importc: "mysql_stmt_affected_rows".}
  1010. proc stmt_insert_id*(stmt: PSTMT): my_ulonglong{.stdcall, dynlib: lib,
  1011. importc: "mysql_stmt_insert_id".}
  1012. proc stmt_field_count*(stmt: PSTMT): cuint{.stdcall, dynlib: lib,
  1013. importc: "mysql_stmt_field_count".}
  1014. proc commit*(MySQL: PMySQL): my_bool{.stdcall, dynlib: lib, importc: "mysql_commit".}
  1015. proc rollback*(MySQL: PMySQL): my_bool{.stdcall, dynlib: lib, importc: "mysql_rollback".}
  1016. proc autocommit*(MySQL: PMySQL, auto_mode: my_bool): my_bool{.stdcall, dynlib: lib,
  1017. importc: "mysql_autocommit".}
  1018. proc more_results*(MySQL: PMySQL): my_bool{.stdcall, dynlib: lib,
  1019. importc: "mysql_more_results".}
  1020. proc next_result*(MySQL: PMySQL): cint{.stdcall, dynlib: lib, importc: "mysql_next_result".}
  1021. proc close*(sock: PMySQL){.stdcall, dynlib: lib, importc: "mysql_close".}
  1022. # status return codes
  1023. const
  1024. NO_DATA* = 100
  1025. DATA_TRUNCATED* = 101
  1026. proc reload*(x: PMySQL): cint
  1027. when defined(USE_OLD_FUNCTIONS):
  1028. proc connect*(MySQL: PMySQL, host: cstring, user: cstring, passwd: cstring): PMySQL{.stdcall,
  1029. dynlib: lib, importc: "mysql_connect".}
  1030. proc create_db*(MySQL: PMySQL, DB: cstring): cint{.stdcall, dynlib: lib,
  1031. importc: "mysql_create_db".}
  1032. proc drop_db*(MySQL: PMySQL, DB: cstring): cint{.stdcall, dynlib: lib,
  1033. importc: "mysql_drop_db".}
  1034. proc net_safe_read*(MySQL: PMySQL): cuint{.cdecl, dynlib: lib, importc: "net_safe_read".}
  1035. proc IS_PRI_KEY(n: int32): bool =
  1036. result = (n and PRI_KEY_FLAG) != 0
  1037. proc IS_NOT_NULL(n: int32): bool =
  1038. result = (n and NOT_NULL_FLAG) != 0
  1039. proc IS_BLOB(n: int32): bool =
  1040. result = (n and BLOB_FLAG) != 0
  1041. proc IS_NUM_FIELD(f: Pst_mysql_field): bool =
  1042. result = (f.flags and NUM_FLAG) != 0
  1043. proc IS_NUM(t: Enum_field_types): bool =
  1044. result = (t <= FIELD_TYPE_INT24) or (t == FIELD_TYPE_YEAR) or
  1045. (t == FIELD_TYPE_NEWDECIMAL)
  1046. proc INTERNAL_NUM_FIELD(f: Pst_mysql_field): bool =
  1047. result = (f.ftype <= FIELD_TYPE_INT24) and
  1048. ((f.ftype != FIELD_TYPE_TIMESTAMP) or (f.len == 14) or (f.len == 8)) or
  1049. (f.ftype == FIELD_TYPE_YEAR)
  1050. proc reload(x: PMySQL): cint =
  1051. result = refresh(x, REFRESH_GRANT)
  1052. {.pop.}
  1053. when defined(nimHasStyleChecks):
  1054. {.pop.}