# src/allographer/query_builder/libs/mysql/mysql_rdb

Theme:

- Index

Search:
Group by:

# Imports

../../../utils

# Types

    BIND = St_mysql_bind

    Charset_info_st {.final.} = object
      number*: cuint
      primary_number*: cuint
      binary_number*: cuint
      state*: cuint
      csname*: cstring
      name*: cstring
      comment*: cstring
      tailoring*: cstring
      ftype*: cstring
      to_lower*: cstring
      to_upper*: cstring
      sort_order*: cstring
      contractions*: ptr int16
      sort_order_big*: ptr ptr int16
      tab_to_uni*: ptr int16
      tab_from_uni*: pointer
      state_map*: cstring
      ident_map*: cstring
      strxfrm_multiply*: cuint
      mbminlen*: cuint
      mbmaxlen*: cuint
      min_sort_char*: int16
      max_sort_char*: int16
      escape_with_backslash_is_dangerous*: my_bool
      cset*: pointer
      coll*: pointer

    cuint = cint

    DATA = St_mysql_data

    Enum_field_types = enum
      TYPE_DECIMAL, TYPE_TINY, TYPE_SHORT, TYPE_LONG, TYPE_FLOAT, TYPE_DOUBLE,
      TYPE_NULL, TYPE_TIMESTAMP, TYPE_LONGLONG, TYPE_INT24, TYPE_DATE, TYPE_TIME,
      TYPE_DATETIME, TYPE_YEAR, TYPE_NEWDATE, TYPE_VARCHAR, TYPE_BIT,
      TYPE_NEWDECIMAL = 246, TYPE_ENUM = 247, TYPE_SET = 248, TYPE_TINY_BLOB = 249,
      TYPE_MEDIUM_BLOB = 250, TYPE_LONG_BLOB = 251, TYPE_BLOB = 252,
      TYPE_VAR_STRING = 253, TYPE_STRING = 254, TYPE_GEOMETRY = 255

    Enum_mysql_stmt_state = enum
      STMT_INIT_DONE = 1, STMT_PREPARE_DONE, STMT_EXECUTE_DONE, STMT_FETCH_DONE

    Enum_server_command {....deprecated.} = enum
      COM_SLEEP, COM_QUIT, COM_INIT_DB, COM_QUERY, COM_FIELD_LIST, COM_CREATE_DB,
      COM_DROP_DB, COM_REFRESH, COM_SHUTDOWN, COM_STATISTICS, COM_PROCESS_INFO,
      COM_CONNECT, COM_PROCESS_KILL, COM_DEBUG, COM_PING, COM_TIME,
      COM_DELAYED_INSERT, COM_CHANGE_USER, COM_BINLOG_DUMP, COM_TABLE_DUMP,
      COM_CONNECT_OUT, COM_REGISTER_SLAVE, COM_STMT_PREPARE, COM_STMT_EXECUTE,
      COM_STMT_SEND_LONG_DATA, COM_STMT_CLOSE, COM_STMT_RESET, COM_SET_OPTION,
      COM_STMT_FETCH, COM_END

  Deprecated

    FIELD = St_mysql_field

    gptr = cstring

    MEM_ROOT = St_mem_root

    my_bool = bool

    my_socket = cint

    my_ulonglong = int64

    NET = St_net

    Option = enum
      OPT_CONNECT_TIMEOUT, OPT_COMPRESS, OPT_NAMED_PIPE, INIT_COMMAND,
      READ_DEFAULT_FILE, READ_DEFAULT_GROUP, SET_CHARSET_DIR, SET_CHARSET_NAME,
      OPT_LOCAL_INFILE, OPT_PROTOCOL, SHARED_MEMORY_BASE_NAME, OPT_READ_TIMEOUT,
      OPT_WRITE_TIMEOUT, OPT_USE_RESULT, OPT_USE_REMOTE_CONNECTION,
      OPT_USE_EMBEDDED_CONNECTION, OPT_GUESS_CONNECTION, SET_CLIENT_IP, SECURE_AUTH,
      REPORT_DATA_TRUNCATION, OPT_RECONNECT, MYSQL_OPT_NONBLOCK

    PBIND = ptr BIND

    Pcharset_info_st = ptr Charset_info_st

    PDATA = ptr DATA

    PFIELD = ptr FIELD

    Pmy_bool = ptr my_bool

    PMySQL = ptr St_mysql

    PNET = ptr NET

    PPByte = pointer

    PRES = ptr RES

    PROWS = ptr ROWS

    Pst_dynamic_array = ptr St_dynamic_array

    Pst_mysql = ptr St_mysql

    Pst_mysql_methods = ptr St_mysql_methods

    Pst_mysql_rows = ptr St_mysql_rows

    Pst_mysql_stmt = ptr St_mysql_stmt

    Pst_used_mem = ptr St_used_mem

    PSTMT = ptr STMT

    PUSED_MEM = ptr USED_MEM

    PVIO = pointer

    RES = St_mysql_res

    ROW = cstringArray

    ROWS = St_mysql_rows

    St_dynamic_array {.final.} = object
      buffer*: cstring
      elements*: cuint
      max_element*: cuint
      alloc_increment*: cuint
      size_of_element*: cuint

    St_mem_root {.final.} = object
      free*: PUSED_MEM
      used*: PUSED_MEM
      pre_alloc*: PUSED_MEM
      min_malloc*: cuint
      block_size*: cuint
      block_num*: cuint
      first_block_usage*: cuint
      error_handler*: proc () {.cdecl.}

    St_mysql {.final.} = object
      net*: NET
      connector_fd*: gptr
      host*: cstring
      user*: cstring
      passwd*: cstring
      unix_socket*: cstring
      server_version*: cstring
      host_info*: cstring
      info*: cstring
      db*: cstring
      charset*: Pcharset_info_st
      fields*: PFIELD
      field_alloc*: MEM_ROOT
      affected_rows*: my_ulonglong
      insert_id*: my_ulonglong
      extra_info*: my_ulonglong
      thread_id*: int
      packet_length*: int
      port*: cuint
      client_flag*: int
      server_capabilities*: int
      protocol_version*: cuint
      field_count*: cuint
      server_status*: cuint
      server_language*: cuint
      warning_count*: cuint
      options*: St_mysql_options
      status*: Status
      free_me*: my_bool
      reconnect*: my_bool
      scramble*: array[0 .. 21 - 1, char]
      rpl_pivot*: my_bool
      master*: Pst_mysql
      next_slave*: Pst_mysql
      last_used_slave*: Pst_mysql
      last_used_con*: Pst_mysql
      stmts*: pointer
      methods*: Pst_mysql_methods
      thd*: pointer
      unbuffered_fetch_owner*: Pmy_bool

    St_mysql_bind {.final.} = object
      length*: ptr culong
      is_null*: Pmy_bool
      buffer*: pointer
      error*: Pmy_bool
      u*: U
      store_param_func*: proc (net: PNET; param: ptr St_mysql_bind) {.cdecl.}
      fetch_result*: proc (param: ptr St_mysql_bind; field: PFIELD; row: PPByte) {.
          cdecl.}
      skip_result*: proc (param: ptr St_mysql_bind; field: PFIELD; row: PPByte) {.
          cdecl.}
      buffer_length*: culong
      offset*: culong
      length_value*: culong
      flags*: cuint
      pack_length*: cuint
      buffer_type*: Enum_field_types
      error_value*: my_bool
      is_unsigned*: my_bool
      long_data_used*: my_bool
      is_null_value*: my_bool
      extension*: pointer

    St_mysql_data {.final.} = object
      rows*: my_ulonglong
      fields*: cuint
      data*: PROWS
      alloc*: MEM_ROOT
      prev_ptr*: ptr PROWS

    St_mysql_field {.final.} = object
      name*: cstring
      org_name*: cstring
      table*: cstring
      org_table*: cstring
      db*: cstring
      catalog*: cstring
      def*: cstring
      len*: int
      max_length*: int
      name_length*: cuint
      org_name_length*: cuint
      table_length*: cuint
      org_table_length*: cuint
      db_length*: cuint
      catalog_length*: cuint
      def_length*: cuint
      flags*: cuint
      decimals*: cuint
      charsetnr*: cuint
      ftype*: Enum_field_types
      extension*: pointer

    St_mysql_methods {.final.} = object
      read_query_result*: proc (MySQL: PMySQL): my_bool {.cdecl.}
      advanced_command*: proc (MySQL: PMySQL; command: Enum_server_command;
                               header: cstring; header_length: int; arg: cstring;
                               arg_length: int; skip_check: my_bool): my_bool
      read_rows*: proc (MySQL: PMySQL; fields: PFIELD; fields_count: cuint): PDATA
      use_result*: proc (MySQL: PMySQL): PRES
      fetch_lengths*: proc (fto: ptr int; column: ROW; field_count: cuint)
      flush_use_result*: proc (MySQL: PMySQL)
      list_fields*: proc (MySQL: PMySQL): PFIELD
      read_prepare_result*: proc (MySQL: PMySQL; stmt: PSTMT): my_bool
      stmt_execute*: proc (stmt: PSTMT): cint
      read_binary_rows*: proc (stmt: PSTMT): cint
      unbuffered_fetch*: proc (MySQL: PMySQL; row: cstringArray): cint
      free_embedded_thd*: proc (MySQL: PMySQL)
      read_statistics*: proc (MySQL: PMySQL): cstring
      next_result*: proc (MySQL: PMySQL): my_bool
      read_change_user_result*: proc (MySQL: PMySQL; buff: cstring; passwd: cstring): cint
      read_rowsfrom_cursor*: proc (stmt: PSTMT): cint

    St_mysql_options {.final.} = object
      connect_timeout*: cuint
      read_timeout*: cuint
      write_timeout*: cuint
      port*: cuint
      protocol*: cuint
      client_flag*: int
      host*: cstring
      user*: cstring
      password*: cstring
      unix_socket*: cstring
      db*: cstring
      init_commands*: Pst_dynamic_array
      my_cnf_file*: cstring
      my_cnf_group*: cstring
      charset_dir*: cstring
      charset_name*: cstring
      ssl_key*: cstring
      ssl_cert*: cstring
      ssl_ca*: cstring
      ssl_capath*: cstring
      ssl_cipher*: cstring
      shared_memory_base_name*: cstring
      max_allowed_packet*: int
      use_ssl*: my_bool
      compress*: my_bool
      named_pipe*: my_bool
      rpl_probe*: my_bool
      rpl_parse*: my_bool
      no_master_reads*: my_bool
      separate_thread*: my_bool
      methods_to_use*: Option
      client_ip*: cstring
      secure_auth*: my_bool
      report_data_truncation*: my_bool
      local_infile_init*: proc (para1: var pointer; para2: cstring; para3: pointer): cint {.
          cdecl.}
      local_infile_read*: proc (para1: pointer; para2: cstring; para3: cuint): cint
      local_infile_end*: proc (para1: pointer)
      local_infile_error*: proc (para1: pointer; para2: cstring; para3: cuint): cint
      local_infile_userdata*: pointer

    St_mysql_res {.final.} = object
      row_count*: my_ulonglong
      fields*: PFIELD
      data*: PDATA
      data_cursor*: PROWS
      lengths*: ptr int
      handle*: PMySQL
      field_alloc*: MEM_ROOT
      field_count*: cuint
      current_field*: cuint
      row*: ROW
      current_row*: ROW
      eof*: my_bool
      unbuffered_fetch_cancelled*: my_bool
      methods*: Pst_mysql_methods

    St_mysql_rows {.final.} = object
      next*: Pst_mysql_rows
      data*: ROW
      len*: int

    St_mysql_stmt {.final.} = object
      mem_root*: MEM_ROOT
      mysql*: PMySQL
      params*: PBIND
      fields*: PFIELD
      result*: DATA
      data_cursor*: PROWS
      affected_rows*: my_ulonglong
      insert_id*: my_ulonglong
      read_row_func*: proc (stmt: Pst_mysql_stmt; row: PPByte): cint {.cdecl.}
      stmt_id*: int
      flags*: int
      prefetch_rows*: int
      server_status*: cuint
      last_errno*: cuint
      param_count*: cuint
      field_count*: cuint
      state*: Enum_mysql_stmt_state
      last_error*: array[0 .. 200 - 1, char]
      sqlstate*: array[0 .. 6 - 1, char]
      send_types_to_server*: my_bool
      bind_param_done*: my_bool
      bind_result_done*: char
      unbuffered_fetch_cancelled*: my_bool
      update_max_length*: my_bool

    St_net {.final.} = object
      vio*: PVIO
      buff*: cstring
      buff_end*: cstring
      write_pos*: cstring
      read_pos*: cstring
      fd*: my_socket
      max_packet*: int
      max_packet_size*: int
      pkt_nr*: cuint
      compress_pkt_nr*: cuint
      write_timeout*: cuint
      read_timeout*: cuint
      retry_count*: cuint
      fcntl*: cint
      compress*: my_bool
      remain_in_buf*: int
      len*: int
      buf_length*: int
      where_b*: int
      return_status*: ptr cint
      reading_or_writing*: char
      save_char*: cchar
      no_send_ok*: my_bool
      no_send_eof*: my_bool
      no_send_error*: my_bool
      last_error*: array[0 .. 200 - 1, char]
      sqlstate*: array[0 .. 6 - 1, char]
      last_errno*: cuint
      error*: char
      query_cache_query*: gptr
      report_error*: my_bool
      return_errno*: my_bool

    St_used_mem {.final.} = object
      next*: Pst_used_mem
      left*: cuint
      size*: cuint

    Status = enum
      STATUS_READY, STATUS_GET_RESULT, STATUS_USE_RESULT

    STMT = St_mysql_stmt

    U {.final, union, pure.} = object

    USED_MEM = St_used_mem

# Consts

    ERRMSG_SIZE = 200

    NOT_NULL_FLAG = 1

    PRI_KEY_FLAG = 2

    SCRAMBLE_LENGTH = 20

    SQLSTATE_LENGTH = 5

# Procs

    proc close(sock: PMySQL) {.stdcall, dynlib: lib, importc: "mysql_close",
                               ...raises: [], tags: [], forbids: [].}

    proc error(MySQL: PMySQL): cstring {.stdcall, dynlib: lib,
                                         importc: "mysql_error", ...raises: [],
                                         tags: [], forbids: [].}

    proc fetch_field_direct(res: PRES; fieldnr: cuint): PFIELD {.stdcall,
        dynlib: lib, importc: "mysql_fetch_field_direct", ...raises: [], tags: [],
        forbids: [].}

    proc fetch_row(result: PRES): ROW {.stdcall, dynlib: lib,
                                        importc: "mysql_fetch_row", ...raises: [],
                                        tags: [], forbids: [].}

    proc free_result(result: PRES) {.stdcall, dynlib: lib,
                                     importc: "mysql_free_result", ...raises: [],
                                     tags: [], forbids: [].}

    proc init(MySQL: PMySQL): PMySQL {.stdcall, dynlib: lib, importc: "mysql_init",
                                       ...raises: [], tags: [], forbids: [].}

    proc init(MySQL: var PMySQL) {.stdcall, dynlib: lib, importc: "mysql_init",
                                   ...raises: [], tags: [], forbids: [].}

    proc num_fields(res: PRES): cuint {.stdcall, dynlib: lib,
                                        importc: "mysql_num_fields", ...raises: [],
                                        tags: [], forbids: [].}

    proc ping(MySQL: PMySQL): cint {.stdcall, dynlib: lib, importc: "mysql_ping",
                                     ...raises: [], tags: [], forbids: [].}

    proc real_connect(MySQL: PMySQL; host: cstring; user: cstring; passwd: cstring;
                      db: cstring; port: cuint; unix_socket: cstring;
                      clientflag: int): PMySQL {.stdcall, dynlib: lib,
        importc: "mysql_real_connect", ...raises: [], tags: [], forbids: [].}

    proc real_escape_string(MySQL: PMySQL; fto: cstring; from: cstring; len: int): int {.
        stdcall, dynlib: lib, importc: "mysql_real_escape_string", ...raises: [],
        tags: [], forbids: [].}

    proc real_query(MySQL: PMySQL; q: cstring; len: int): cint {.stdcall,
        dynlib: lib, importc: "mysql_real_query", ...raises: [], tags: [], forbids: [].}

    proc stmt_init(MySQL: PMySQL): PSTMT {.stdcall, dynlib: lib,
                                           importc: "mysql_stmt_init", ...raises: [],
                                           tags: [], forbids: [].}

    proc use_result(MySQL: PMySQL): PRES {.stdcall, dynlib: lib,
                                           importc: "mysql_use_result", ...raises: [],
                                           tags: [], forbids: [].}