mysql.nim 52 KB

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