summary refs log tree commit diff stats
path: root/lib/base
diff options
context:
space:
mode:
Diffstat (limited to 'lib/base')
-rw-r--r--lib/base/libcurl.nim642
-rw-r--r--lib/base/mysql.nim1155
-rw-r--r--lib/base/sqlite3.nim376
-rw-r--r--lib/base/terminal.nim310
-rw-r--r--lib/base/web.nim57
5 files changed, 2540 insertions, 0 deletions
diff --git a/lib/base/libcurl.nim b/lib/base/libcurl.nim
new file mode 100644
index 000000000..5d54a2640
--- /dev/null
+++ b/lib/base/libcurl.nim
@@ -0,0 +1,642 @@
+#
+#    $Id: header,v 1.1 2000/07/13 06:33:45 michael Exp $
+#    This file is part of the Free Pascal packages
+#    Copyright (c) 1999-2000 by the Free Pascal development team
+#
+#    See the file COPYING.FPC, included in this distribution,
+#    for details about the copyright.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# **********************************************************************
+#
+#   the curl library is governed by its own copyright, see the curl
+#   website for this. 
+# 
+
+import times
+
+when defined(windows):
+  const libname = "libcurl.dll"
+elif defined(macosx):
+  const libname = "libcurl-7.19.3.dylib"
+elif defined(unix):
+  const libname = "libcurl.so.4"
+
+type 
+  Pcurl_calloc_callback* = ptr Tcurl_calloc_callback
+  Pcurl_closepolicy* = ptr Tcurl_closepolicy
+  Pcurl_forms* = ptr Tcurl_forms
+  Pcurl_ftpauth* = ptr Tcurl_ftpauth
+  Pcurl_ftpmethod* = ptr Tcurl_ftpmethod
+  Pcurl_ftpssl* = ptr Tcurl_ftpssl
+  PCURL_HTTP_VERSION* = ptr TCURL_HTTP_VERSION
+  Pcurl_httppost* = ptr Tcurl_httppost
+  PPcurl_httppost* = ptr Pcurl_httppost
+  Pcurl_infotype* = ptr Tcurl_infotype
+  Pcurl_lock_access* = ptr Tcurl_lock_access
+  Pcurl_lock_data* = ptr Tcurl_lock_data
+  Pcurl_malloc_callback* = ptr tcurl_malloc_callback
+  PCURL_NETRC_OPTION* = ptr TCURL_NETRC_OPTION
+  Pcurl_proxytype* = ptr Tcurl_proxytype
+  Pcurl_realloc_callback* = ptr tcurl_realloc_callback
+  Pcurl_slist* = ptr Tcurl_slist
+  Pcurl_socket* = ptr Tcurl_socket
+  PCURL_SSL_VERSION* = ptr TCURL_SSL_VERSION
+  Pcurl_strdup_callback* = ptr Tcurl_strdup_callback
+  PCURL_TIMECOND* = ptr TCURL_TIMECOND
+  Pcurl_version_info_data* = ptr Tcurl_version_info_data
+  PCURLcode* = ptr TCURLcode
+  PCURLFORMcode* = ptr TCURLFORMcode
+  PCURLformoption* = ptr TCURLformoption
+  PCURLINFO* = ptr TCURLINFO
+  Pcurliocmd* = ptr Tcurliocmd
+  Pcurlioerr* = ptr Tcurlioerr
+  PCURLM* = ptr TCURLM
+  PCURLMcode* = ptr TCURLMcode
+  PCURLMoption* = ptr TCURLMoption
+  PCURLMSG* = ptr TCURLMSG
+  PCURLoption* = ptr TCURLoption
+  PCURLSH* = ptr TCURLSH
+  PCURLSHcode* = ptr TCURLSHcode
+  PCURLSHoption* = ptr TCURLSHoption
+  PCURLversion* = ptr TCURLversion
+  Pfd_set* = pointer
+  PCURL* = ptr TCurl
+  TCurl* = pointer
+  Tcurl_httppost* {.final, pure.} = object 
+    next*: Pcurl_httppost
+    name*: cstring
+    namelength*: int32
+    contents*: cstring
+    contentslength*: int32
+    buffer*: cstring
+    bufferlength*: int32
+    contenttype*: cstring
+    contentheader*: Pcurl_slist
+    more*: Pcurl_httppost
+    flags*: int32
+    showfilename*: cstring
+
+  Tcurl_progress_callback* = proc (clientp: pointer, dltotal: float64, 
+                                   dlnow: float64, ultotal: float64, 
+                                   ulnow: float64): int32{.cdecl.}
+  Tcurl_write_callback* = proc (buffer: cstring, size: int, nitems: int, 
+                                outstream: pointer): int{.cdecl.}
+  Tcurl_read_callback* = proc (buffer: cstring, size: int, nitems: int, 
+                               instream: pointer): int{.cdecl.}
+  Tcurl_passwd_callback* = proc (clientp: pointer, prompt: cstring, 
+                                 buffer: cstring, buflen: int32): int32{.cdecl.}
+  Tcurlioerr* = enum 
+    CURLIOE_OK, CURLIOE_UNKNOWNCMD, CURLIOE_FAILRESTART, CURLIOE_LAST
+  Tcurliocmd* = enum 
+    CURLIOCMD_NOP, CURLIOCMD_RESTARTREAD, CURLIOCMD_LAST
+  Tcurl_ioctl_callback* = proc (handle: PCURL, cmd: int32, 
+                                clientp: pointer): Tcurlioerr {.cdecl.}
+  Tcurl_malloc_callback* = proc (size: int): pointer {.cdecl.}
+  Tcurl_free_callback* = proc (p: pointer) {.cdecl.}
+  Tcurl_realloc_callback* = proc (p: pointer, size: int): pointer {.cdecl.}
+  Tcurl_strdup_callback* = proc (str: cstring): cstring {.cdecl.}
+  Tcurl_calloc_callback* = proc (nmemb: int, size: int): pointer
+  Tcurl_infotype* = enum 
+    CURLINFO_TEXT = 0, CURLINFO_HEADER_IN, CURLINFO_HEADER_OUT, 
+    CURLINFO_DATA_IN, CURLINFO_DATA_OUT, CURLINFO_SSL_DATA_IN, 
+    CURLINFO_SSL_DATA_OUT, CURLINFO_END
+  Tcurl_debug_callback* = proc (handle: PCURL, theType: Tcurl_infotype, 
+                                data: cstring, size: int, 
+                                userptr: pointer): int32 {.cdecl.}
+  TCURLcode* = enum 
+    CURLE_OK = 0, CURLE_UNSUPPORTED_PROTOCOL, CURLE_FAILED_INIT, 
+    CURLE_URL_MALFORMAT, CURLE_URL_MALFORMAT_USER, CURLE_COULDNT_RESOLVE_PROXY, 
+    CURLE_COULDNT_RESOLVE_HOST, CURLE_COULDNT_CONNECT, 
+    CURLE_FTP_WEIRD_SERVER_REPLY, CURLE_FTP_ACCESS_DENIED, 
+    CURLE_FTP_USER_PASSWORD_INCORRECT, CURLE_FTP_WEIRD_PASS_REPLY, 
+    CURLE_FTP_WEIRD_USER_REPLY, CURLE_FTP_WEIRD_PASV_REPLY, 
+    CURLE_FTP_WEIRD_227_FORMAT, CURLE_FTP_CANT_GET_HOST, 
+    CURLE_FTP_CANT_RECONNECT, CURLE_FTP_COULDNT_SET_BINARY, CURLE_PARTIAL_FILE, 
+    CURLE_FTP_COULDNT_RETR_FILE, CURLE_FTP_WRITE_ERROR, CURLE_FTP_QUOTE_ERROR, 
+    CURLE_HTTP_RETURNED_ERROR, CURLE_WRITE_ERROR, CURLE_MALFORMAT_USER, 
+    CURLE_FTP_COULDNT_STOR_FILE, CURLE_READ_ERROR, CURLE_OUT_OF_MEMORY, 
+    CURLE_OPERATION_TIMEOUTED, CURLE_FTP_COULDNT_SET_ASCII, 
+    CURLE_FTP_PORT_FAILED, CURLE_FTP_COULDNT_USE_REST, 
+    CURLE_FTP_COULDNT_GET_SIZE, CURLE_HTTP_RANGE_ERROR, CURLE_HTTP_POST_ERROR, 
+    CURLE_SSL_CONNECT_ERROR, CURLE_BAD_DOWNLOAD_RESUME, 
+    CURLE_FILE_COULDNT_READ_FILE, CURLE_LDAP_CANNOT_BIND, 
+    CURLE_LDAP_SEARCH_FAILED, CURLE_LIBRARY_NOT_FOUND, CURLE_FUNCTION_NOT_FOUND, 
+    CURLE_ABORTED_BY_CALLBACK, CURLE_BAD_FUNCTION_ARGUMENT, 
+    CURLE_BAD_CALLING_ORDER, CURLE_INTERFACE_FAILED, CURLE_BAD_PASSWORD_ENTERED, 
+    CURLE_TOO_MANY_REDIRECTS, CURLE_UNKNOWN_TELNET_OPTION, 
+    CURLE_TELNET_OPTION_SYNTAX, CURLE_OBSOLETE, CURLE_SSL_PEER_CERTIFICATE, 
+    CURLE_GOT_NOTHING, CURLE_SSL_ENGINE_NOTFOUND, CURLE_SSL_ENGINE_SETFAILED, 
+    CURLE_SEND_ERROR, CURLE_RECV_ERROR, CURLE_SHARE_IN_USE, 
+    CURLE_SSL_CERTPROBLEM, CURLE_SSL_CIPHER, CURLE_SSL_CACERT, 
+    CURLE_BAD_CONTENT_ENCODING, CURLE_LDAP_INVALID_URL, CURLE_FILESIZE_EXCEEDED, 
+    CURLE_FTP_SSL_FAILED, CURLE_SEND_FAIL_REWIND, CURLE_SSL_ENGINE_INITFAILED, 
+    CURLE_LOGIN_DENIED, CURLE_TFTP_NOTFOUND, CURLE_TFTP_PERM, 
+    CURLE_TFTP_DISKFULL, CURLE_TFTP_ILLEGAL, CURLE_TFTP_UNKNOWNID, 
+    CURLE_TFTP_EXISTS, CURLE_TFTP_NOSUCHUSER, CURLE_CONV_FAILED, 
+    CURLE_CONV_REQD, CURL_LAST
+  Tcurl_conv_callback* = proc (buffer: cstring, len: int): TCURLcode {.cdecl.}
+  Tcurl_ssl_ctx_callback* = proc (curl: PCURL, 
+                                 ssl_ctx, userptr: pointer): TCURLcode {.cdecl.}
+  Tcurl_proxytype* = enum 
+    CURLPROXY_HTTP = 0, CURLPROXY_SOCKS4 = 4, CURLPROXY_SOCKS5 = 5
+  Tcurl_ftpssl* = enum 
+    CURLFTPSSL_NONE, CURLFTPSSL_TRY, CURLFTPSSL_CONTROL, CURLFTPSSL_ALL, 
+    CURLFTPSSL_LAST
+  Tcurl_ftpauth* = enum 
+    CURLFTPAUTH_DEFAULT, CURLFTPAUTH_SSL, CURLFTPAUTH_TLS, CURLFTPAUTH_LAST
+  Tcurl_ftpmethod* = enum 
+    CURLFTPMETHOD_DEFAULT, CURLFTPMETHOD_MULTICWD, CURLFTPMETHOD_NOCWD, 
+    CURLFTPMETHOD_SINGLECWD, CURLFTPMETHOD_LAST
+  TCURLoption* = enum 
+    CURLOPT_PORT = 0 + 3,
+    CURLOPT_TIMEOUT = 0 + 13, 
+    CURLOPT_INFILESIZE = 0 + 14, 
+    CURLOPT_LOW_SPEED_LIMIT = 0 + 19, 
+    CURLOPT_LOW_SPEED_TIME = 0 + 20, 
+    CURLOPT_RESUME_FROM = 0 + 21,
+    CURLOPT_CRLF = 0 + 27, 
+    CURLOPT_SSLVERSION = 0 + 32, 
+    CURLOPT_TIMECONDITION = 0 + 33, 
+    CURLOPT_TIMEVALUE = 0 + 34, 
+    CURLOPT_VERBOSE = 0 + 41, 
+    CURLOPT_HEADER = 0 + 42, 
+    CURLOPT_NOPROGRESS = 0 + 43, 
+    CURLOPT_NOBODY = 0 + 44, 
+    CURLOPT_FAILONERROR = 0 + 45, 
+    CURLOPT_UPLOAD = 0 + 46, 
+    CURLOPT_POST = 0 + 47, 
+    CURLOPT_FTPLISTONLY = 0 + 48, 
+    CURLOPT_FTPAPPEND = 0 + 50, 
+    CURLOPT_NETRC = 0 + 51, 
+    CURLOPT_FOLLOWLOCATION = 0 + 52, 
+    CURLOPT_TRANSFERTEXT = 0 + 53, 
+    CURLOPT_PUT = 0 + 54, 
+    CURLOPT_AUTOREFERER = 0 + 58, 
+    CURLOPT_PROXYPORT = 0 + 59, 
+    CURLOPT_POSTFIELDSIZE = 0 + 60, 
+    CURLOPT_HTTPPROXYTUNNEL = 0 + 61, 
+    CURLOPT_SSL_VERIFYPEER = 0 + 64, 
+    CURLOPT_MAXREDIRS = 0 + 68, 
+    CURLOPT_FILETIME = 0 + 69, 
+    CURLOPT_MAXCONNECTS = 0 + 71, 
+    CURLOPT_CLOSEPOLICY = 0 + 72, 
+    CURLOPT_FRESH_CONNECT = 0 + 74, 
+    CURLOPT_FORBID_REUSE = 0 + 75, 
+    CURLOPT_CONNECTTIMEOUT = 0 + 78, 
+    CURLOPT_HTTPGET = 0 + 80, 
+    CURLOPT_SSL_VERIFYHOST = 0 + 81, 
+    CURLOPT_HTTP_VERSION = 0 + 84, 
+    CURLOPT_FTP_USE_EPSV = 0 + 85, 
+    CURLOPT_SSLENGINE_DEFAULT = 0 + 90, 
+    CURLOPT_DNS_USE_GLOBAL_CACHE = 0 + 91, 
+    CURLOPT_DNS_CACHE_TIMEOUT = 0 + 92, 
+    CURLOPT_COOKIESESSION = 0 + 96, 
+    CURLOPT_BUFFERSIZE = 0 + 98, 
+    CURLOPT_NOSIGNAL = 0 + 99, 
+    CURLOPT_PROXYTYPE = 0 + 101, 
+    CURLOPT_UNRESTRICTED_AUTH = 0 + 105, 
+    CURLOPT_FTP_USE_EPRT = 0 + 106, 
+    CURLOPT_HTTPAUTH = 0 + 107, 
+    CURLOPT_FTP_CREATE_MISSING_DIRS = 0 + 110, 
+    CURLOPT_PROXYAUTH = 0 + 111, 
+    CURLOPT_FTP_RESPONSE_TIMEOUT = 0 + 112, 
+    CURLOPT_IPRESOLVE = 0 + 113, 
+    CURLOPT_MAXFILESIZE = 0 + 114, 
+    CURLOPT_FTP_SSL = 0 + 119, 
+    CURLOPT_TCP_NODELAY = 0 + 121, 
+    CURLOPT_FTPSSLAUTH = 0 + 129, 
+    CURLOPT_IGNORE_CONTENT_LENGTH = 0 + 136, 
+    CURLOPT_FTP_SKIP_PASV_IP = 0 + 137, 
+    CURLOPT_FTP_FILEMETHOD = 0 + 138, 
+    CURLOPT_LOCALPORT = 0 + 139, 
+    CURLOPT_LOCALPORTRANGE = 0 + 140, 
+    CURLOPT_CONNECT_ONLY = 0 + 141, 
+
+    CURLOPT_FILE = 10000 + 1, 
+    CURLOPT_URL = 10000 + 2,  
+    CURLOPT_PROXY = 10000 + 4, 
+    CURLOPT_USERPWD = 10000 + 5, 
+    CURLOPT_PROXYUSERPWD = 10000 + 6, 
+    CURLOPT_RANGE = 10000 + 7, 
+    CURLOPT_INFILE = 10000 + 9, 
+    CURLOPT_ERRORBUFFER = 10000 + 10, 
+    CURLOPT_POSTFIELDS = 10000 + 15, 
+    CURLOPT_REFERER = 10000 + 16, 
+    CURLOPT_FTPPORT = 10000 + 17, 
+    CURLOPT_USERAGENT = 10000 + 18, 
+    CURLOPT_COOKIE = 10000 + 22, 
+    CURLOPT_HTTPHEADER = 10000 + 23, 
+    CURLOPT_HTTPPOST = 10000 + 24, 
+    CURLOPT_SSLCERT = 10000 + 25, 
+    CURLOPT_SSLCERTPASSWD = 10000 + 26, 
+    CURLOPT_QUOTE = 10000 + 28, 
+    CURLOPT_WRITEHEADER = 10000 + 29, 
+    CURLOPT_COOKIEFILE = 10000 + 31, 
+    CURLOPT_CUSTOMREQUEST = 10000 + 36, 
+    CURLOPT_STDERR = 10000 + 37, 
+    CURLOPT_POSTQUOTE = 10000 + 39, 
+    CURLOPT_WRITEINFO = 10000 + 40, 
+    CURLOPT_PROGRESSDATA = 10000 + 57, 
+    CURLOPT_INTERFACE = 10000 + 62, 
+    CURLOPT_KRB4LEVEL = 10000 + 63,
+    CURLOPT_CAINFO = 10000 + 65, 
+    CURLOPT_TELNETOPTIONS = 10000 + 70, 
+    CURLOPT_RANDOM_FILE = 10000 + 76, 
+    CURLOPT_EGDSOCKET = 10000 + 77, 
+    CURLOPT_COOKIEJAR = 10000 + 82, 
+    CURLOPT_SSL_CIPHER_LIST = 10000 + 83, 
+    CURLOPT_SSLCERTTYPE = 10000 + 86, 
+    CURLOPT_SSLKEY = 10000 + 87, 
+    CURLOPT_SSLKEYTYPE = 10000 + 88, 
+    CURLOPT_SSLENGINE = 10000 + 89, 
+    CURLOPT_PREQUOTE = 10000 + 93, 
+    CURLOPT_DEBUGDATA = 10000 + 95, 
+    CURLOPT_CAPATH = 10000 + 97, 
+    CURLOPT_SHARE = 10000 + 100, 
+    CURLOPT_ENCODING = 10000 + 102, 
+    CURLOPT_PRIVATE = 10000 + 103, 
+    CURLOPT_HTTP200ALIASES = 10000 + 104, 
+    CURLOPT_SSL_CTX_DATA = 10000 + 109, 
+    CURLOPT_NETRC_FILE = 10000 + 118, 
+    CURLOPT_SOURCE_USERPWD = 10000 + 123, 
+    CURLOPT_SOURCE_PREQUOTE = 10000 + 127, 
+    CURLOPT_SOURCE_POSTQUOTE = 10000 + 128, 
+    CURLOPT_IOCTLDATA = 10000 + 131, 
+    CURLOPT_SOURCE_URL = 10000 + 132, 
+    CURLOPT_SOURCE_QUOTE = 10000 + 133, 
+    CURLOPT_FTP_ACCOUNT = 10000 + 134, 
+    CURLOPT_COOKIELIST = 10000 + 135, 
+    CURLOPT_FTP_ALTERNATIVE_TO_USER = 10000 + 147, 
+    CURLOPT_LASTENTRY = 10000 + 148,
+    
+    CURLOPT_WRITEFUNCTION = 20000 + 11, 
+    CURLOPT_READFUNCTION = 20000 + 12, 
+    CURLOPT_PROGRESSFUNCTION = 20000 + 56, 
+    CURLOPT_HEADERFUNCTION = 20000 + 79, 
+    CURLOPT_DEBUGFUNCTION = 20000 + 94, 
+    CURLOPT_SSL_CTX_FUNCTION = 20000 + 108, 
+    CURLOPT_IOCTLFUNCTION = 20000 + 130, 
+    CURLOPT_CONV_FROM_NETWORK_FUNCTION = 20000 + 142, 
+    CURLOPT_CONV_TO_NETWORK_FUNCTION = 20000 + 143, 
+    CURLOPT_CONV_FROM_UTF8_FUNCTION = 20000 + 144, 
+
+    CURLOPT_INFILESIZE_LARGE = 30000 + 115, 
+    CURLOPT_RESUME_FROM_LARGE = 30000 + 116, 
+    CURLOPT_MAXFILESIZE_LARGE = 30000 + 117, 
+    CURLOPT_POSTFIELDSIZE_LARGE = 30000 + 120, 
+    CURLOPT_MAX_SEND_SPEED_LARGE = 30000 + 145, 
+    CURLOPT_MAX_RECV_SPEED_LARGE = 30000 + 146
+
+    
+  TCURL_HTTP_VERSION* = enum 
+    CURL_HTTP_VERSION_NONE, CURL_HTTP_VERSION_1_0, CURL_HTTP_VERSION_1_1, 
+    CURL_HTTP_VERSION_LAST
+    
+  TCURL_NETRC_OPTION* = enum 
+    CURL_NETRC_IGNORED, CURL_NETRC_OPTIONAL, CURL_NETRC_REQUIRED, 
+    CURL_NETRC_LAST
+    
+  TCURL_SSL_VERSION* = enum 
+    CURL_SSLVERSION_DEFAULT, CURL_SSLVERSION_TLSv1, CURL_SSLVERSION_SSLv2, 
+    CURL_SSLVERSION_SSLv3, CURL_SSLVERSION_LAST
+  
+  TCURL_TIMECOND* = enum 
+    CURL_TIMECOND_NONE, CURL_TIMECOND_IFMODSINCE, CURL_TIMECOND_IFUNMODSINCE, 
+    CURL_TIMECOND_LASTMOD, CURL_TIMECOND_LAST
+  
+  TCURLformoption* = enum 
+    CURLFORM_NOTHING, CURLFORM_COPYNAME, CURLFORM_PTRNAME, CURLFORM_NAMELENGTH, 
+    CURLFORM_COPYCONTENTS, CURLFORM_PTRCONTENTS, CURLFORM_CONTENTSLENGTH, 
+    CURLFORM_FILECONTENT, CURLFORM_ARRAY, CURLFORM_OBSOLETE, CURLFORM_FILE, 
+    CURLFORM_BUFFER, CURLFORM_BUFFERPTR, CURLFORM_BUFFERLENGTH, 
+    CURLFORM_CONTENTTYPE, CURLFORM_CONTENTHEADER, CURLFORM_FILENAME, 
+    CURLFORM_END, CURLFORM_OBSOLETE2, CURLFORM_LASTENTRY
+  
+  Tcurl_forms* {.pure, final.} = object 
+    option*: TCURLformoption
+    value*: cstring
+
+  TCURLFORMcode* = enum 
+    CURL_FORMADD_OK, CURL_FORMADD_MEMORY, CURL_FORMADD_OPTION_TWICE, 
+    CURL_FORMADD_NULL, CURL_FORMADD_UNKNOWN_OPTION, CURL_FORMADD_INCOMPLETE, 
+    CURL_FORMADD_ILLEGAL_ARRAY, CURL_FORMADD_DISABLED, CURL_FORMADD_LAST
+
+  Tcurl_formget_callback* = proc (arg: pointer, buf: cstring, 
+                                 length: int): int {.cdecl.}
+  Tcurl_slist* {.pure, final.} = object 
+    data*: cstring
+    next*: Pcurl_slist
+
+  TCURLINFO* = enum 
+    CURLINFO_NONE = 0, 
+    CURLINFO_LASTONE = 30,
+    CURLINFO_EFFECTIVE_URL = 0x00100000 + 1, 
+    CURLINFO_CONTENT_TYPE = 0x00100000 + 18, 
+    CURLINFO_PRIVATE = 0x00100000 + 21, 
+    CURLINFO_FTP_ENTRY_PATH = 0x00100000 + 30,
+
+    CURLINFO_RESPONSE_CODE = 0x00200000 + 2, 
+    CURLINFO_HEADER_SIZE = 0x00200000 + 11, 
+    CURLINFO_REQUEST_SIZE = 0x00200000 + 12, 
+    CURLINFO_SSL_VERIFYRESULT = 0x00200000 + 13, 
+    CURLINFO_FILETIME = 0x00200000 + 14, 
+    CURLINFO_REDIRECT_COUNT = 0x00200000 + 20, 
+    CURLINFO_HTTP_CONNECTCODE = 0x00200000 + 22, 
+    CURLINFO_HTTPAUTH_AVAIL = 0x00200000 + 23, 
+    CURLINFO_PROXYAUTH_AVAIL = 0x00200000 + 24, 
+    CURLINFO_OS_ERRNO = 0x00200000 + 25, 
+    CURLINFO_NUM_CONNECTS = 0x00200000 + 26, 
+    CURLINFO_LASTSOCKET = 0x00200000 + 29, 
+    
+    CURLINFO_TOTAL_TIME = 0x00300000 + 3, 
+    CURLINFO_NAMELOOKUP_TIME = 0x00300000 + 4, 
+    CURLINFO_CONNECT_TIME = 0x00300000 + 5, 
+    CURLINFO_PRETRANSFER_TIME = 0x00300000 + 6, 
+    CURLINFO_SIZE_UPLOAD = 0x00300000 + 7, 
+    CURLINFO_SIZE_DOWNLOAD = 0x00300000 + 8, 
+    CURLINFO_SPEED_DOWNLOAD = 0x00300000 + 9, 
+    CURLINFO_SPEED_UPLOAD = 0x00300000 + 10, 
+    CURLINFO_CONTENT_LENGTH_DOWNLOAD = 0x00300000 + 15, 
+    CURLINFO_CONTENT_LENGTH_UPLOAD = 0x00300000 + 16, 
+    CURLINFO_STARTTRANSFER_TIME = 0x00300000 + 17, 
+    CURLINFO_REDIRECT_TIME = 0x00300000 + 19, 
+
+    CURLINFO_SSL_ENGINES = 0x00400000 + 27, 
+    CURLINFO_COOKIELIST = 0x00400000 + 28
+
+  Tcurl_closepolicy* = enum 
+    CURLCLOSEPOLICY_NONE, CURLCLOSEPOLICY_OLDEST, 
+    CURLCLOSEPOLICY_LEAST_RECENTLY_USED, CURLCLOSEPOLICY_LEAST_TRAFFIC, 
+    CURLCLOSEPOLICY_SLOWEST, CURLCLOSEPOLICY_CALLBACK, CURLCLOSEPOLICY_LAST
+  Tcurl_lock_data* = enum 
+    CURL_LOCK_DATA_NONE = 0, CURL_LOCK_DATA_SHARE, CURL_LOCK_DATA_COOKIE, 
+    CURL_LOCK_DATA_DNS, CURL_LOCK_DATA_SSL_SESSION, CURL_LOCK_DATA_CONNECT, 
+    CURL_LOCK_DATA_LAST
+  Tcurl_lock_access* = enum 
+    CURL_LOCK_ACCESS_NONE = 0, CURL_LOCK_ACCESS_SHARED = 1, 
+    CURL_LOCK_ACCESS_SINGLE = 2, CURL_LOCK_ACCESS_LAST
+  
+  Tcurl_lock_function* = proc (handle: PCURL, data: Tcurl_lock_data, 
+                              locktype: Tcurl_lock_access, 
+                              userptr: pointer) {.cdecl.}
+  Tcurl_unlock_function* = proc (handle: PCURL, data: Tcurl_lock_data, 
+                                userptr: pointer) {.cdecl.}
+  TCURLSH* = pointer
+  TCURLSHcode* = enum 
+    CURLSHE_OK, CURLSHE_BAD_OPTION, CURLSHE_IN_USE, CURLSHE_INVALID, 
+    CURLSHE_NOMEM, CURLSHE_LAST
+  
+  TCURLSHoption* = enum 
+    CURLSHOPT_NONE, CURLSHOPT_SHARE, CURLSHOPT_UNSHARE, CURLSHOPT_LOCKFUNC, 
+    CURLSHOPT_UNLOCKFUNC, CURLSHOPT_USERDATA, CURLSHOPT_LAST
+  
+  TCURLversion* = enum 
+    CURLVERSION_FIRST, CURLVERSION_SECOND, CURLVERSION_THIRD, CURLVERSION_LAST
+  
+  Tcurl_version_info_data* {.pure, final.} = object 
+    age*: TCURLversion
+    version*: cstring
+    version_num*: int32
+    host*: cstring
+    features*: int32
+    ssl_version*: cstring
+    ssl_version_num*: int32
+    libz_version*: cstring
+    protocols*: cstringArray
+    ares*: cstring
+    ares_num*: int32
+    libidn*: cstring
+    iconv_ver_num*: int32
+
+  TCURLM* = pointer
+  Tcurl_socket* = int32
+  TCURLMcode* = enum 
+    CURLM_CALL_MULTI_PERFORM = -1, 
+    CURLM_OK = 0, 
+    CURLM_BAD_HANDLE, 
+    CURLM_BAD_EASY_HANDLE, 
+    CURLM_OUT_OF_MEMORY, 
+    CURLM_INTERNAL_ERROR, 
+    CURLM_BAD_SOCKET, 
+    CURLM_UNKNOWN_OPTION, 
+    CURLM_LAST
+    
+  TCURLMSGEnum* = enum 
+    CURLMSG_NONE, CURLMSG_DONE, CURLMSG_LAST
+  TCURLMsg* {.pure, final.} = object 
+    msg*: TCURLMSGEnum
+    easy_handle*: PCURL
+    whatever*: Pointer        #data : record
+                              #      case longint of
+                              #        0 : ( whatever : pointer );
+                              #        1 : ( result : CURLcode );
+                              #    end;
+  
+  Tcurl_socket_callback* = proc (easy: PCURL, s: Tcurl_socket, what: int32, 
+                                 userp, socketp: pointer): int32 {.cdecl.}
+  TCURLMoption* = enum 
+    CURLMOPT_SOCKETDATA = 10000 + 2, 
+    CURLMOPT_LASTENTRY = 10000 + 3,
+    CURLMOPT_SOCKETFUNCTION = 20000 + 1
+    
+const 
+  CURLOPT_SSLKEYPASSWD* = CURLOPT_SSLCERTPASSWD
+
+  CURLAUTH_ANY* = not (0)
+  CURLAUTH_BASIC* = 1 shl 0
+  CURLAUTH_ANYSAFE* = not (CURLAUTH_BASIC)
+  CURLAUTH_DIGEST* = 1 shl 1
+  CURLAUTH_GSSNEGOTIATE* = 1 shl 2
+  CURLAUTH_NONE* = 0
+  CURLAUTH_NTLM* = 1 shl 3
+  CURLE_ALREADY_COMPLETE* = 99999
+  CURLE_FTP_BAD_DOWNLOAD_RESUME* = CURLE_BAD_DOWNLOAD_RESUME
+  CURLE_FTP_PARTIAL_FILE* = CURLE_PARTIAL_FILE
+  CURLE_HTTP_NOT_FOUND* = CURLE_HTTP_RETURNED_ERROR
+  CURLE_HTTP_PORT_FAILED* = CURLE_INTERFACE_FAILED
+  CURLE_OPERATION_TIMEDOUT* = CURLE_OPERATION_TIMEOUTED
+  CURL_ERROR_SIZE* = 256
+  CURL_FORMAT_OFF_T* = "%ld"
+  CURL_GLOBAL_NOTHING* = 0
+  CURL_GLOBAL_SSL* = 1 shl 0
+  CURL_GLOBAL_WIN32* = 1 shl 1
+  CURL_GLOBAL_ALL* = CURL_GLOBAL_SSL or CURL_GLOBAL_WIN32
+  CURL_GLOBAL_DEFAULT* = CURL_GLOBAL_ALL
+  CURLINFO_DOUBLE* = 0x00300000
+  CURLINFO_HTTP_CODE* = CURLINFO_RESPONSE_CODE
+  CURLINFO_LONG* = 0x00200000
+  CURLINFO_MASK* = 0x000FFFFF
+  CURLINFO_SLIST* = 0x00400000
+  CURLINFO_STRING* = 0x00100000
+  CURLINFO_TYPEMASK* = 0x00F00000
+  CURL_IPRESOLVE_V4* = 1
+  CURL_IPRESOLVE_V6* = 2
+  CURL_IPRESOLVE_WHATEVER* = 0
+  CURL_MAX_WRITE_SIZE* = 16384
+  CURLM_CALL_MULTI_SOCKET* = CURLM_CALL_MULTI_PERFORM
+  CURLOPT_CLOSEFUNCTION* = - (5)
+  CURLOPT_FTPASCII* = CURLOPT_TRANSFERTEXT
+  CURLOPT_HEADERDATA* = CURLOPT_WRITEHEADER
+  CURLOPT_HTTPREQUEST* = - (1)
+  CURLOPT_MUTE* = - (2)
+  CURLOPT_PASSWDDATA* = - (4)
+  CURLOPT_PASSWDFUNCTION* = - (3)
+  CURLOPT_PASV_HOST* = - (9)
+  CURLOPT_READDATA* = CURLOPT_INFILE
+  CURLOPT_SOURCE_HOST* = - (6)
+  CURLOPT_SOURCE_PATH* = - (7)
+  CURLOPT_SOURCE_PORT* = - (8)
+  CURLOPTTYPE_FUNCTIONPOINT* = 20000
+  CURLOPTTYPE_LONG* = 0
+  CURLOPTTYPE_OBJECTPOINT* = 10000
+  CURLOPTTYPE_OFF_T* = 30000
+  CURLOPT_WRITEDATA* = CURLOPT_FILE
+  CURL_POLL_IN* = 1
+  CURL_POLL_INOUT* = 3
+  CURL_POLL_NONE* = 0
+  CURL_POLL_OUT* = 2
+  CURL_POLL_REMOVE* = 4
+  CURL_READFUNC_ABORT* = 0x10000000
+  CURL_SOCKET_BAD* = - (1)
+  CURL_SOCKET_TIMEOUT* = CURL_SOCKET_BAD
+  CURL_VERSION_ASYNCHDNS* = 1 shl 7
+  CURL_VERSION_CONV* = 1 shl 12
+  CURL_VERSION_DEBUG* = 1 shl 6
+  CURL_VERSION_GSSNEGOTIATE* = 1 shl 5
+  CURL_VERSION_IDN* = 1 shl 10
+  CURL_VERSION_IPV6* = 1 shl 0
+  CURL_VERSION_KERBEROS4* = 1 shl 1
+  CURL_VERSION_LARGEFILE* = 1 shl 9
+  CURL_VERSION_LIBZ* = 1 shl 3
+  CURLVERSION_NOW* = CURLVERSION_THIRD
+  CURL_VERSION_NTLM* = 1 shl 4
+  CURL_VERSION_SPNEGO* = 1 shl 8
+  CURL_VERSION_SSL* = 1 shl 2
+  CURL_VERSION_SSPI* = 1 shl 11
+  FILE_OFFSET_BITS* = 0
+  FILESIZEBITS* = 0
+  FUNCTIONPOINT* = CURLOPTTYPE_FUNCTIONPOINT
+  HTTPPOST_BUFFER* = 1 shl 4
+  HTTPPOST_FILENAME* = 1 shl 0
+  HTTPPOST_PTRBUFFER* = 1 shl 5
+  HTTPPOST_PTRCONTENTS* = 1 shl 3
+  HTTPPOST_PTRNAME* = 1 shl 2
+  HTTPPOST_READFILE* = 1 shl 1
+  LIBCURL_VERSION* = "7.15.5"
+  LIBCURL_VERSION_MAJOR* = 7
+  LIBCURL_VERSION_MINOR* = 15
+  LIBCURL_VERSION_NUM* = 0x00070F05
+  LIBCURL_VERSION_PATCH* = 5
+
+proc curl_strequal*(s1, s2: cstring): int32{.cdecl, 
+    dynlib: libname, importc: "curl_strequal".}
+proc curl_strnequal*(s1, s2: cstring, n: int): int32 {.cdecl, 
+    dynlib: libname, importc: "curl_strnequal".}
+proc curl_formadd*(httppost, last_post: PPcurl_httppost): TCURLFORMcode {.
+    cdecl, varargs, dynlib: libname, importc: "curl_formadd".}
+
+proc curl_formget*(form: Pcurl_httppost, arg: pointer, 
+                   append: Tcurl_formget_callback): int32 {.cdecl, 
+    dynlib: libname, importc: "curl_formget".}
+proc curl_formfree*(form: Pcurl_httppost){.cdecl, dynlib: libname, 
+    importc: "curl_formfree".}
+proc curl_getenv*(variable: cstring): cstring{.cdecl, dynlib: libname, 
+    importc: "curl_getenv".}
+proc curl_version*(): cstring{.cdecl, dynlib: libname, importc: "curl_version".}
+proc curl_easy_escape*(handle: PCURL, str: cstring, len: int32): cstring{.cdecl, 
+    dynlib: libname, importc: "curl_easy_escape".}
+proc curl_escape*(str: cstring, len: int32): cstring{.cdecl, 
+    dynlib: libname, importc: "curl_escape".}
+proc curl_easy_unescape*(handle: PCURL, str: cstring, len: int32, 
+                         outlength: var int32): cstring{.cdecl, 
+    dynlib: libname, importc: "curl_easy_unescape".}
+proc curl_unescape*(str: cstring, len: int32): cstring{.cdecl, 
+    dynlib: libname, importc: "curl_unescape".}
+proc curl_free*(p: pointer){.cdecl, dynlib: libname, 
+                             importc: "curl_free".}
+proc curl_global_init*(flags: int32): TCURLcode {.cdecl, dynlib: libname, 
+    importc: "curl_global_init".}
+proc curl_global_init_mem*(flags: int32, m: Tcurl_malloc_callback, 
+                           f: Tcurl_free_callback, r: Tcurl_realloc_callback, 
+                           s: Tcurl_strdup_callback, 
+                           c: Tcurl_calloc_callback): TCURLcode {.
+    cdecl, dynlib: libname, importc: "curl_global_init_mem".}
+proc curl_global_cleanup*() {.cdecl, dynlib: libname, 
+                              importc: "curl_global_cleanup".}
+proc curl_slist_append*(curl_slist: Pcurl_slist, P: cstring): Pcurl_slist {.
+    cdecl, dynlib: libname, importc: "curl_slist_append".}
+proc curl_slist_free_all*(para1: Pcurl_slist) {.cdecl, dynlib: libname, 
+    importc: "curl_slist_free_all".}
+proc curl_getdate*(p: cstring, unused: ptr TTime): TTime {.cdecl, 
+    dynlib: libname, importc: "curl_getdate".}
+proc curl_share_init*(): PCURLSH{.cdecl, dynlib: libname, 
+                                  importc: "curl_share_init".}
+proc curl_share_setopt*(para1: PCURLSH, option: TCURLSHoption): TCURLSHcode {.
+    cdecl, varargs, dynlib: libname, importc: "curl_share_setopt".}
+
+proc curl_share_cleanup*(para1: PCURLSH): TCURLSHcode {.cdecl, 
+    dynlib: libname, importc: "curl_share_cleanup".}
+proc curl_version_info*(para1: TCURLversion): Pcurl_version_info_data{.cdecl, 
+    dynlib: libname, importc: "curl_version_info".}
+proc curl_easy_strerror*(para1: TCURLcode): cstring {.cdecl, 
+    dynlib: libname, importc: "curl_easy_strerror".}
+proc curl_share_strerror*(para1: TCURLSHcode): cstring {.cdecl, 
+    dynlib: libname, importc: "curl_share_strerror".}
+proc curl_easy_init*(): PCURL {.cdecl, dynlib: libname, 
+                               importc: "curl_easy_init".}
+proc curl_easy_setopt*(curl: PCURL, option: TCURLoption): TCURLcode {.cdecl, 
+    varargs, dynlib: libname, importc: "curl_easy_setopt".}
+
+proc curl_easy_perform*(curl: PCURL): TCURLcode {.cdecl, dynlib: libname, 
+    importc: "curl_easy_perform".}
+proc curl_easy_cleanup*(curl: PCURL) {.cdecl, dynlib: libname, 
+                                       importc: "curl_easy_cleanup".}
+proc curl_easy_getinfo*(curl: PCURL, info: TCURLINFO): TCURLcode {.
+    cdecl, varargs, dynlib: libname, importc: "curl_easy_getinfo".}
+
+proc curl_easy_duphandle*(curl: PCURL): PCURL {.cdecl, dynlib: libname, 
+    importc: "curl_easy_duphandle".}
+proc curl_easy_reset*(curl: PCURL) {.cdecl, dynlib: libname, 
+                                     importc: "curl_easy_reset".}
+proc curl_multi_init*(): PCURLM {.cdecl, dynlib: libname, 
+                                  importc: "curl_multi_init".}
+proc curl_multi_add_handle*(multi_handle: PCURLM, 
+                            curl_handle: PCURL): TCURLMcode {.
+    cdecl, dynlib: libname, importc: "curl_multi_add_handle".}
+proc curl_multi_remove_handle*(multi_handle: PCURLM, 
+                               curl_handle: PCURL): TCURLMcode {.
+    cdecl, dynlib: libname, importc: "curl_multi_remove_handle".}
+proc curl_multi_fdset*(multi_handle: PCURLM, read_fd_set: Pfd_set, 
+                       write_fd_set: Pfd_set, exc_fd_set: Pfd_set, 
+                       max_fd: var int32): TCURLMcode {.cdecl, 
+    dynlib: libname, importc: "curl_multi_fdset".}
+proc curl_multi_perform*(multi_handle: PCURLM, 
+                         running_handles: var int32): TCURLMcode {.
+    cdecl, dynlib: libname, importc: "curl_multi_perform".}
+proc curl_multi_cleanup*(multi_handle: PCURLM): TCURLMcode {.cdecl, 
+    dynlib: libname, importc: "curl_multi_cleanup".}
+proc curl_multi_info_read*(multi_handle: PCURLM, 
+                           msgs_in_queue: var int32): PCURLMsg {.
+    cdecl, dynlib: libname, importc: "curl_multi_info_read".}
+proc curl_multi_strerror*(para1: TCURLMcode): cstring {.cdecl, 
+    dynlib: libname, importc: "curl_multi_strerror".}
+proc curl_multi_socket*(multi_handle: PCURLM, s: Tcurl_socket, 
+                        running_handles: var int32): TCURLMcode {.cdecl, 
+    dynlib: libname, importc: "curl_multi_socket".}
+proc curl_multi_socket_all*(multi_handle: PCURLM, 
+                            running_handles: var int32): TCURLMcode {.
+    cdecl, dynlib: libname, importc: "curl_multi_socket_all".}
+proc curl_multi_timeout*(multi_handle: PCURLM, milliseconds: var int32): TCURLMcode{.
+    cdecl, dynlib: libname, importc: "curl_multi_timeout".}
+proc curl_multi_setopt*(multi_handle: PCURLM, option: TCURLMoption): TCURLMcode{.
+    cdecl, varargs, dynlib: libname, importc: "curl_multi_setopt".}
+
+proc curl_multi_assign*(multi_handle: PCURLM, sockfd: Tcurl_socket, 
+                        sockp: pointer): TCURLMcode {.cdecl, 
+    dynlib: libname, importc: "curl_multi_assign".}
+
+
diff --git a/lib/base/mysql.nim b/lib/base/mysql.nim
new file mode 100644
index 000000000..60c6bd80c
--- /dev/null
+++ b/lib/base/mysql.nim
@@ -0,0 +1,1155 @@
+#
+#
+#            Nimrod's Runtime Library
+#        (c) Copyright 2009 Andreas Rumpf
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+{.deadCodeElim: on.}
+
+when defined(Unix): 
+  const 
+    mysqllib = "libmysqlclient.so.15"
+
+# mysqllib = "libmysqlclient.so.15"
+when defined(Windows): 
+  const
+    mysqllib = "libmysql.dll"
+    
+# Copyright (C) 2000-2003 MySQL AB
+#  
+#     This program is free software; you can redistribute it and/or modify
+#     it under the terms of the GNU General Public License as published by
+#     the Free Software Foundation; either version 2 of the License, or
+#     (at your option) any later version.
+#  
+#     This program is distributed in the hope that it will be useful,
+#     but WITHOUT ANY WARRANTY; without even the implied warranty of
+#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#     GNU General Public License for more details.
+#  
+#     You should have received a copy of the GNU General Public License
+#     along with this program; if not, write to the Free Software
+#     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
+
+type 
+  my_bool* = bool
+  Pmy_bool* = ptr my_bool
+  PVIO* = Pointer
+  Pgptr* = ptr gptr
+  gptr* = cstring
+  Pmy_socket* = ptr my_socket
+  my_socket* = cint
+  PPByte* = pointer 
+  cuint* = cint
+  
+#  ------------ Start of declaration in "mysql_com.h"   ---------------------  
+#
+#  ** Common definition between mysql server & client
+#   
+# Field/table name length
+
+const 
+  NAME_LEN* = 64
+  HOSTNAME_LENGTH* = 60
+  USERNAME_LENGTH* = 16
+  SERVER_VERSION_LENGTH* = 60
+  SQLSTATE_LENGTH* = 5
+  LOCAL_HOST* = "localhost"
+  LOCAL_HOST_NAMEDPIPE* = '.'
+
+const 
+  MYSQL_NAMEDPIPE* = "MySQL"
+  MYSQL_SERVICENAME* = "MySQL"
+
+type 
+  enum_server_command* = 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
+
+const 
+  SCRAMBLE_LENGTH* = 20 # Length of random string sent by server on handshake; 
+                        # this is also length of obfuscated password, 
+                        # recieved from client
+  SCRAMBLE_LENGTH_323* = 8 # length of password stored in the db: 
+                           # new passwords are preceeded with '*'  
+  SCRAMBLED_PASSWORD_CHAR_LENGTH* = SCRAMBLE_LENGTH * 2 + 1
+  SCRAMBLED_PASSWORD_CHAR_LENGTH_323* = SCRAMBLE_LENGTH_323 * 2
+  NOT_NULL_FLAG* = 1          #  Field can't be NULL
+  PRI_KEY_FLAG* = 2           #  Field is part of a primary key
+  UNIQUE_KEY_FLAG* = 4        #  Field is part of a unique key
+  MULTIPLE_KEY_FLAG* = 8      #  Field is part of a key
+  BLOB_FLAG* = 16             #  Field is a blob
+  UNSIGNED_FLAG* = 32         #  Field is unsigned
+  ZEROFILL_FLAG* = 64         #  Field is zerofill
+  BINARY_FLAG* = 128          #  Field is binary
+                              # The following are only sent to new clients  
+  ENUM_FLAG* = 256            # field is an enum
+  AUTO_INCREMENT_FLAG* = 512  # field is a autoincrement field
+  TIMESTAMP_FLAG* = 1024      # Field is a timestamp
+  SET_FLAG* = 2048            # field is a set
+  NO_DEFAULT_VALUE_FLAG* = 4096 # Field doesn't have default value
+  NUM_FLAG* = 32768           # Field is num (for clients)
+  PART_KEY_FLAG* = 16384      # Intern; Part of some key
+  GROUP_FLAG* = 32768         # Intern: Group field
+  UNIQUE_FLAG* = 65536        # Intern: Used by sql_yacc
+  BINCMP_FLAG* = 131072       # Intern: Used by sql_yacc
+  REFRESH_GRANT* = 1          # Refresh grant tables
+  REFRESH_LOG* = 2            # Start on new log file
+  REFRESH_TABLES* = 4         # close all tables
+  REFRESH_HOSTS* = 8          # Flush host cache
+  REFRESH_STATUS* = 16        # Flush status variables
+  REFRESH_THREADS* = 32       # Flush thread cache
+  REFRESH_SLAVE* = 64         # Reset master info and restart slave thread
+  REFRESH_MASTER* = 128 # Remove all bin logs in the index and truncate the index
+                        # The following can't be set with mysql_refresh()  
+  REFRESH_READ_LOCK* = 16384  # Lock tables for read
+  REFRESH_FAST* = 32768       # Intern flag
+  REFRESH_QUERY_CACHE* = 65536 # RESET (remove all queries) from query cache
+  REFRESH_QUERY_CACHE_FREE* = 0x00020000 # pack query cache
+  REFRESH_DES_KEY_FILE* = 0x00040000
+  REFRESH_USER_RESOURCES* = 0x00080000
+  CLIENT_LONG_PASSWORD* = 1   # new more secure passwords
+  CLIENT_FOUND_ROWS* = 2      # Found instead of affected rows
+  CLIENT_LONG_FLAG* = 4       # Get all column flags
+  CLIENT_CONNECT_WITH_DB* = 8 # One can specify db on connect
+  CLIENT_NO_SCHEMA* = 16      # Don't allow database.table.column
+  CLIENT_COMPRESS* = 32       # Can use compression protocol
+  CLIENT_ODBC* = 64           # Odbc client
+  CLIENT_LOCAL_FILES* = 128   # Can use LOAD DATA LOCAL
+  CLIENT_IGNORE_SPACE* = 256  # Ignore spaces before '('
+  CLIENT_PROTOCOL_41* = 512   # New 4.1 protocol
+  CLIENT_INTERACTIVE* = 1024  # This is an interactive client
+  CLIENT_SSL* = 2048          # Switch to SSL after handshake
+  CLIENT_IGNORE_SIGPIPE* = 4096 # IGNORE sigpipes
+  CLIENT_TRANSACTIONS* = 8192 # Client knows about transactions
+  CLIENT_RESERVED* = 16384    # Old flag for 4.1 protocol
+  CLIENT_SECURE_CONNECTION* = 32768 # New 4.1 authentication
+  CLIENT_MULTI_STATEMENTS* = 65536 # Enable/disable multi-stmt support
+  CLIENT_MULTI_RESULTS* = 131072 # Enable/disable multi-results
+  CLIENT_REMEMBER_OPTIONS*: int = 1 shl 31
+  SERVER_STATUS_IN_TRANS* = 1 # Transaction has started
+  SERVER_STATUS_AUTOCOMMIT* = 2 # Server in auto_commit mode
+  SERVER_STATUS_MORE_RESULTS* = 4 # More results on server
+  SERVER_MORE_RESULTS_EXISTS* = 8 # Multi query - next query exists
+  SERVER_QUERY_NO_GOOD_INDEX_USED* = 16
+  SERVER_QUERY_NO_INDEX_USED* = 32 # The server was able to fulfill the clients request and opened a
+                                   #      read-only non-scrollable cursor for a query. This flag comes
+                                   #      in reply to COM_STMT_EXECUTE and COM_STMT_FETCH commands. 
+  SERVER_STATUS_CURSOR_EXISTS* = 64 # This flag is sent when a read-only cursor is exhausted, in reply to
+                                    #      COM_STMT_FETCH command. 
+  SERVER_STATUS_LAST_ROW_SENT* = 128
+  SERVER_STATUS_DB_DROPPED* = 256 # A database was dropped
+  SERVER_STATUS_NO_BACKSLASH_ESCAPES* = 512
+  MYSQL_ERRMSG_SIZE* = 200
+  NET_READ_TIMEOUT* = 30      # Timeout on read
+  NET_WRITE_TIMEOUT* = 60     # Timeout on write
+  NET_WAIT_TIMEOUT* = 8 * 60 * 60 # Wait for new query
+  ONLY_KILL_QUERY* = 1
+
+const 
+  MAX_TINYINT_WIDTH* = 3      # Max width for a TINY w.o. sign
+  MAX_SMALLINT_WIDTH* = 5     # Max width for a SHORT w.o. sign
+  MAX_MEDIUMINT_WIDTH* = 8    # Max width for a INT24 w.o. sign
+  MAX_INT_WIDTH* = 10         # Max width for a LONG w.o. sign
+  MAX_BIGINT_WIDTH* = 20      # Max width for a LONGLONG
+  MAX_CHAR_WIDTH* = 255       # Max length for a CHAR colum
+  MAX_BLOB_WIDTH* = 8192      # Default width for blob
+
+type 
+  Pst_net* = ptr st_net
+  st_net*{.final.} = object
+    vio*: PVio
+    buff*: cstring
+    buff_end*: cstring
+    write_pos*: cstring
+    read_pos*: cstring
+    fd*: my_socket            # For Perl DBI/dbd
+    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 #   The following variable is set if we are doing several queries in one
+                       #        command ( as in LOAD TABLE ... FROM MASTER ),
+                       #        and do not want to confuse the client with OK at the wrong time 
+    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      # For SPs and other things that do multiple stmts
+    no_send_eof*: my_bool     # For SPs' first version read-only cursors
+    no_send_error*: my_bool # Set if OK packet is already sent, and
+                            # we do not need to send error messages
+                            #   Pointer to query object in query cache, do not equal NULL (0) for
+                            #        queries in cache that have not stored its results yet 
+                            # $endif
+    last_error*: array[0..(MYSQL_ERRMSG_SIZE) - 1, char]
+    sqlstate*: array[0..(SQLSTATE_LENGTH + 1) - 1, char]
+    last_errno*: cuint
+    error*: char
+    query_cache_query*: gptr
+    report_error*: my_bool    # We should report error (we have unreported error)
+    return_errno*: my_bool
+
+  NET* = st_net
+  PNET* = ptr NET
+
+const 
+  packet_error* = -1
+
+type 
+  enum_field_types* = enum    # For backward compatibility  
+    MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG, 
+    MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE, MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP, 
+    MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INT24, MYSQL_TYPE_DATE, MYSQL_TYPE_TIME, 
+    MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR, MYSQL_TYPE_NEWDATE, 
+    MYSQL_TYPE_VARCHAR, MYSQL_TYPE_BIT, MYSQL_TYPE_NEWDECIMAL = 246, 
+    MYSQL_TYPE_ENUM = 247, MYSQL_TYPE_SET = 248, MYSQL_TYPE_TINY_BLOB = 249, 
+    MYSQL_TYPE_MEDIUM_BLOB = 250, MYSQL_TYPE_LONG_BLOB = 251, 
+    MYSQL_TYPE_BLOB = 252, MYSQL_TYPE_VAR_STRING = 253, MYSQL_TYPE_STRING = 254, 
+    MYSQL_TYPE_GEOMETRY = 255
+
+const 
+  CLIENT_MULTI_QUERIES* = CLIENT_MULTI_STATEMENTS
+  FIELD_TYPE_DECIMAL* = MYSQL_TYPE_DECIMAL
+  FIELD_TYPE_NEWDECIMAL* = MYSQL_TYPE_NEWDECIMAL
+  FIELD_TYPE_TINY* = MYSQL_TYPE_TINY
+  FIELD_TYPE_SHORT* = MYSQL_TYPE_SHORT
+  FIELD_TYPE_LONG* = MYSQL_TYPE_LONG
+  FIELD_TYPE_FLOAT* = MYSQL_TYPE_FLOAT
+  FIELD_TYPE_DOUBLE* = MYSQL_TYPE_DOUBLE
+  FIELD_TYPE_NULL* = MYSQL_TYPE_NULL
+  FIELD_TYPE_TIMESTAMP* = MYSQL_TYPE_TIMESTAMP
+  FIELD_TYPE_LONGLONG* = MYSQL_TYPE_LONGLONG
+  FIELD_TYPE_INT24* = MYSQL_TYPE_INT24
+  FIELD_TYPE_DATE* = MYSQL_TYPE_DATE
+  FIELD_TYPE_TIME* = MYSQL_TYPE_TIME
+  FIELD_TYPE_DATETIME* = MYSQL_TYPE_DATETIME
+  FIELD_TYPE_YEAR* = MYSQL_TYPE_YEAR
+  FIELD_TYPE_NEWDATE* = MYSQL_TYPE_NEWDATE
+  FIELD_TYPE_ENUM* = MYSQL_TYPE_ENUM
+  FIELD_TYPE_SET* = MYSQL_TYPE_SET
+  FIELD_TYPE_TINY_BLOB* = MYSQL_TYPE_TINY_BLOB
+  FIELD_TYPE_MEDIUM_BLOB* = MYSQL_TYPE_MEDIUM_BLOB
+  FIELD_TYPE_LONG_BLOB* = MYSQL_TYPE_LONG_BLOB
+  FIELD_TYPE_BLOB* = MYSQL_TYPE_BLOB
+  FIELD_TYPE_VAR_STRING* = MYSQL_TYPE_VAR_STRING
+  FIELD_TYPE_STRING* = MYSQL_TYPE_STRING
+  FIELD_TYPE_CHAR* = MYSQL_TYPE_TINY
+  FIELD_TYPE_INTERVAL* = MYSQL_TYPE_ENUM
+  FIELD_TYPE_GEOMETRY* = MYSQL_TYPE_GEOMETRY
+  FIELD_TYPE_BIT* = MYSQL_TYPE_BIT # Shutdown/kill enums and constants  
+                                   # Bits for THD::killable.  
+  MYSQL_SHUTDOWN_KILLABLE_CONNECT* = chr(1 shl 0)
+  MYSQL_SHUTDOWN_KILLABLE_TRANS* = chr(1 shl 1)
+  MYSQL_SHUTDOWN_KILLABLE_LOCK_TABLE* = chr(1 shl 2)
+  MYSQL_SHUTDOWN_KILLABLE_UPDATE* = chr(1 shl 3)
+  
+type 
+  mysql_enum_shutdown_level* = enum 
+    SHUTDOWN_DEFAULT = 0, SHUTDOWN_WAIT_CONNECTIONS = 1,  
+    SHUTDOWN_WAIT_TRANSACTIONS = 2,  
+    SHUTDOWN_WAIT_UPDATES = 8,  
+    SHUTDOWN_WAIT_ALL_BUFFERS = 16, 
+    SHUTDOWN_WAIT_CRITICAL_BUFFERS = 17,  
+    KILL_QUERY = 254,        
+    KILL_CONNECTION = 255
+  enum_cursor_type* = enum    # options for mysql_set_option  
+    CURSOR_TYPE_NO_CURSOR = 0, CURSOR_TYPE_READ_ONLY = 1, 
+    CURSOR_TYPE_FOR_UPDATE = 2, CURSOR_TYPE_SCROLLABLE = 4
+  enum_mysql_set_option* = enum 
+    MYSQL_OPTION_MULTI_STATEMENTS_ON, MYSQL_OPTION_MULTI_STATEMENTS_OFF
+
+proc net_new_transaction*(net: st_net): st_net
+proc my_net_init*(net: PNET, vio: PVio): my_bool{.cdecl, dynlib: mysqllib, 
+    importc: "my_net_init".}
+proc my_net_local_init*(net: PNET){.cdecl, dynlib: mysqllib, 
+                                    importc: "my_net_local_init".}
+proc net_end*(net: PNET){.cdecl, dynlib: mysqllib, importc: "net_end".}
+proc net_clear*(net: PNET){.cdecl, dynlib: mysqllib, importc: "net_clear".}
+proc net_realloc*(net: PNET, len: int): my_bool{.cdecl, dynlib: mysqllib, 
+    importc: "net_realloc".}
+proc net_flush*(net: PNET): my_bool{.cdecl, dynlib: mysqllib, 
+                                     importc: "net_flush".}
+proc my_net_write*(net: PNET, packet: cstring, length: int): my_bool{.cdecl, 
+    dynlib: mysqllib, importc: "my_net_write".}
+proc net_write_command*(net: PNET, command: char, header: cstring, 
+                        head_len: int, packet: cstring, length: int): my_bool{.
+    cdecl, dynlib: mysqllib, importc: "net_write_command".}
+proc net_real_write*(net: PNET, packet: cstring, length: int): cint{.cdecl, 
+    dynlib: mysqllib, importc: "net_real_write".}
+proc my_net_read*(net: PNET): int{.cdecl, dynlib: mysqllib, 
+                                      importc: "my_net_read".}
+  # The following function is not meant for normal usage
+  #      Currently it's used internally by manager.c  
+type 
+  Psockaddr* = ptr sockaddr
+  sockaddr*{.final.} = object  # undefined structure
+
+proc my_connect*(s: my_socket, name: Psockaddr, namelen: cuint, timeout: cuint): cint{.
+    cdecl, dynlib: mysqllib, importc: "my_connect".}
+type 
+  Prand_struct* = ptr rand_struct
+  rand_struct*{.final.} = object  # The following is for user defined functions  
+    seed1*: int
+    seed2*: int
+    max_value*: int
+    max_value_dbl*: cdouble
+
+  Item_result* = enum 
+    STRING_RESULT, REAL_RESULT, INT_RESULT, ROW_RESULT, DECIMAL_RESULT
+  PItem_result* = ptr Item_result
+  Pst_udf_args* = ptr st_udf_args
+  st_udf_args*{.final.} = object 
+    arg_count*: cuint         # Number of arguments
+    arg_type*: PItem_result   # Pointer to item_results
+    args*: cstringArray             # Pointer to item_results
+    lengths*: ptr int         # Length of string arguments
+    maybe_null*: cstring      # Length of string arguments
+    attributes*: cstringArray       # Pointer to attribute name
+    attribute_lengths*: ptr int # Length of attribute arguments
+  
+  UDF_ARGS* = st_udf_args
+  PUDF_ARGS* = ptr UDF_ARGS   # This holds information about the result  
+  Pst_udf_init* = ptr st_udf_init
+  st_udf_init*{.final.} = object 
+    maybe_null*: my_bool      # 1 if function can return NULL
+    decimals*: cuint          # for real functions
+    max_length*: int          # For string functions
+    theptr*: cstring          # free pointer for function data
+    const_item*: my_bool      # free pointer for function data
+  
+  UDF_INIT* = st_udf_init
+  PUDF_INIT* = ptr UDF_INIT   # Constants when using compression  
+
+const 
+  NET_HEADER_SIZE* = 4        # standard header size
+  COMP_HEADER_SIZE* = 3 # compression header extra size
+                        # Prototypes to password functions  
+                        # These functions are used for authentication by client and server and
+                        #      implemented in sql/password.c     
+
+proc randominit*(para1: Prand_struct, seed1: int, seed2: int){.cdecl, 
+    dynlib: mysqllib, importc: "randominit".}
+proc my_rnd*(para1: Prand_struct): cdouble{.cdecl, dynlib: mysqllib, 
+    importc: "my_rnd".}
+proc create_random_string*(fto: cstring, len: cuint, rand_st: Prand_struct){.
+    cdecl, dynlib: mysqllib, importc: "create_random_string".}
+proc hash_password*(fto: int, password: cstring, password_len: cuint){.cdecl, 
+    dynlib: mysqllib, importc: "hash_password".}
+proc make_scrambled_password_323*(fto: cstring, password: cstring){.cdecl, 
+    dynlib: mysqllib, importc: "make_scrambled_password_323".}
+proc scramble_323*(fto: cstring, message: cstring, password: cstring){.cdecl, 
+    dynlib: mysqllib, importc: "scramble_323".}
+proc check_scramble_323*(para1: cstring, message: cstring, salt: int): my_bool{.
+    cdecl, dynlib: mysqllib, importc: "check_scramble_323".}
+proc get_salt_from_password_323*(res: ptr int, password: cstring){.cdecl, 
+    dynlib: mysqllib, importc: "get_salt_from_password_323".}
+proc make_password_from_salt_323*(fto: cstring, salt: ptr int){.cdecl, 
+    dynlib: mysqllib, importc: "make_password_from_salt_323".}
+proc octet2hex*(fto: cstring, str: cstring, length: cuint): cstring{.cdecl, 
+    dynlib: mysqllib, importc: "octet2hex".}
+proc make_scrambled_password*(fto: cstring, password: cstring){.cdecl, 
+    dynlib: mysqllib, importc: "make_scrambled_password".}
+proc scramble*(fto: cstring, message: cstring, password: cstring){.cdecl, 
+    dynlib: mysqllib, importc: "scramble".}
+proc check_scramble*(reply: cstring, message: cstring, hash_stage2: pointer): my_bool{.
+    cdecl, dynlib: mysqllib, importc: "check_scramble".}
+proc get_salt_from_password*(res: pointer, password: cstring){.cdecl, 
+    dynlib: mysqllib, importc: "get_salt_from_password".}
+proc make_password_from_salt*(fto: cstring, hash_stage2: pointer){.cdecl, 
+    dynlib: mysqllib, importc: "make_password_from_salt".}
+  # end of password.c  
+proc get_tty_password*(opt_message: cstring): cstring{.cdecl, dynlib: mysqllib, 
+    importc: "get_tty_password".}
+proc mysql_errno_to_sqlstate*(mysql_errno: cuint): cstring{.cdecl, 
+    dynlib: mysqllib, importc: "mysql_errno_to_sqlstate".}
+  # Some other useful functions  
+proc modify_defaults_file*(file_location: cstring, option: cstring, 
+                           option_value: cstring, section_name: cstring, 
+                           remove_option: cint): cint{.cdecl, dynlib: mysqllib, 
+    importc: "load_defaults".}
+proc load_defaults*(conf_file: cstring, groups: cstringArray, argc: ptr cint, 
+                    argv: ptr cstringArray): cint{.cdecl, dynlib: mysqllib, 
+    importc: "load_defaults".}
+proc my_init*(): my_bool{.cdecl, dynlib: mysqllib, importc: "my_init".}
+proc my_thread_init*(): my_bool{.cdecl, dynlib: mysqllib, 
+                                 importc: "my_thread_init".}
+proc my_thread_end*(){.cdecl, dynlib: mysqllib, importc: "my_thread_end".}
+const 
+  NULL_LENGTH*: int = int(not (0)) # For net_store_length
+
+const 
+  MYSQL_STMT_HEADER* = 4
+  MYSQL_LONG_DATA_HEADER* = 6 #  ------------ Stop of declaration in "mysql_com.h"   -----------------------  
+                              # $include "mysql_time.h"
+                              # $include "mysql_version.h"
+                              # $include "typelib.h"
+                              # $include "my_list.h" /* for LISTs used in 'MYSQL' and 'MYSQL_STMT' */
+                              #      var
+                              #         mysql_port : cuint;cvar;external;
+                              #         mysql_unix_port : Pchar;cvar;external;
+
+const 
+  CLIENT_NET_READ_TIMEOUT* = 365 * 24 * 3600 # Timeout on read
+  CLIENT_NET_WRITE_TIMEOUT* = 365 * 24 * 3600 # Timeout on write
+
+type 
+  Pst_mysql_field* = ptr st_mysql_field
+  st_mysql_field*{.final.} = object 
+    name*: cstring            # Name of column
+    org_name*: cstring        # Original column name, if an alias
+    table*: cstring           # Table of column if column was a field
+    org_table*: cstring       # Org table name, if table was an alias
+    db*: cstring              # Database for table
+    catalog*: cstring         # Catalog for table
+    def*: cstring             # Default value (set by mysql_list_fields)
+    len*: int              # Width of column (create length)
+    max_length*: int       # Max width for selected set
+    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             # Div flags
+    decimals*: cuint          # Number of decimals in field
+    charsetnr*: cuint         # Character set
+    ftype*: enum_field_types  # Type of field. See mysql_com.h for types
+  
+  MYSQL_FIELD* = st_mysql_field
+  PMYSQL_FIELD* = ptr MYSQL_FIELD
+  PMYSQL_ROW* = ptr MYSQL_ROW # return data as array of strings
+  MYSQL_ROW* = cstringArray
+  PMYSQL_FIELD_OFFSET* = ptr MYSQL_FIELD_OFFSET # offset to current field
+  MYSQL_FIELD_OFFSET* = cuint
+
+proc IS_PRI_KEY*(n: int32): bool
+proc IS_NOT_NULL*(n: int32): bool
+proc IS_BLOB*(n: int32): bool
+proc IS_NUM*(t: enum_field_types): bool
+proc INTERNAL_NUM_FIELD*(f: Pst_mysql_field): bool
+proc IS_NUM_FIELD*(f: Pst_mysql_field): bool
+
+type 
+  my_ulonglong* = int64
+  Pmy_ulonglong* = ptr my_ulonglong
+
+const 
+  MYSQL_COUNT_ERROR* = not (my_ulonglong(0))
+
+type 
+  Pst_mysql_rows* = ptr st_mysql_rows
+  st_mysql_rows*{.final.} = object 
+    next*: Pst_mysql_rows     # list of rows
+    data*: MYSQL_ROW
+    len*: int
+
+  MYSQL_ROWS* = st_mysql_rows
+  PMYSQL_ROWS* = ptr MYSQL_ROWS
+  PMYSQL_ROW_OFFSET* = ptr MYSQL_ROW_OFFSET # offset to current row
+  MYSQL_ROW_OFFSET* = MYSQL_ROWS #  ------------ Start of declaration in "my_alloc.h"     --------------------  
+                                 # $include "my_alloc.h"
+
+const 
+  ALLOC_MAX_BLOCK_TO_DROP* = 4096
+  ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP* = 10 # struct for once_alloc (block)  
+
+type 
+  Pst_used_mem* = ptr st_used_mem
+  st_used_mem*{.final.} = object 
+    next*: Pst_used_mem       # Next block in use
+    left*: cuint              # memory left in block
+    size*: cuint              # size of block
+  
+  USED_MEM* = st_used_mem
+  PUSED_MEM* = ptr USED_MEM
+  Pst_mem_root* = ptr st_mem_root
+  st_mem_root*{.final.} = object 
+    free*: PUSED_MEM          # blocks with free memory in it
+    used*: PUSED_MEM          # blocks almost without free memory
+    pre_alloc*: PUSED_MEM     # preallocated block
+    min_malloc*: cuint        # if block have less memory it will be put in 'used' list
+    block_size*: cuint        # initial block size
+    block_num*: cuint # allocated blocks counter
+                      #    first free block in queue test counter (if it exceed
+                      #       MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)     
+    first_block_usage*: cuint
+    error_handler*: proc (){.cdecl.}
+
+  MEM_ROOT* = st_mem_root
+  PMEM_ROOT* = ptr MEM_ROOT   #  ------------ Stop of declaration in "my_alloc.h"    ----------------------  
+
+type 
+  Pst_mysql_data* = ptr st_mysql_data
+  st_mysql_data*{.final.} = object 
+    rows*: my_ulonglong
+    fields*: cuint
+    data*: PMYSQL_ROWS
+    alloc*: MEM_ROOT
+    prev_ptr*: ptr PMYSQL_ROWS
+
+  MYSQL_DATA* = st_mysql_data
+  PMYSQL_DATA* = ptr MYSQL_DATA
+  mysql_option* = enum 
+    MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE, 
+    MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP, 
+    MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE, 
+    MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT, 
+    MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT, 
+    MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, 
+    MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, 
+    MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT
+
+const 
+  MAX_MYSQL_MANAGER_ERR* = 256
+  MAX_MYSQL_MANAGER_MSG* = 256
+  MANAGER_OK* = 200
+  MANAGER_INFO* = 250
+  MANAGER_ACCESS* = 401
+  MANAGER_CLIENT_ERR* = 450
+  MANAGER_INTERNAL_ERR* = 500
+
+type 
+  st_dynamic_array*{.final.} = object 
+    buffer*: cstring
+    elements*: cuint
+    max_element*: cuint
+    alloc_increment*: cuint
+    size_of_element*: cuint
+
+  DYNAMIC_ARRAY* = st_dynamic_array
+  Pst_dynamic_array* = ptr st_dynamic_array
+  Pst_mysql_options* = ptr st_mysql_options
+  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         # PEM key file
+    ssl_cert*: cstring        # PEM cert file
+    ssl_ca*: cstring          # PEM CA file
+    ssl_capath*: cstring      # PEM directory of CA-s?
+    ssl_cipher*: cstring      # cipher to use
+    shared_memory_base_name*: cstring
+    max_allowed_packet*: int
+    use_ssl*: my_bool         # if to use SSL or not
+    compress*: my_bool
+    named_pipe*: my_bool #  On connect, find out the replication role of the server, and
+                         #       establish connections to all the peers  
+    rpl_probe*: my_bool #  Each call to mysql_real_query() will parse it to tell if it is a read
+                        #       or a write, and direct it to the slave or the master      
+    rpl_parse*: my_bool #  If set, never read from a master, only from slave, when doing
+                        #       a read that is replication-aware    
+    no_master_reads*: my_bool
+    separate_thread*: my_bool
+    methods_to_use*: mysql_option
+    client_ip*: cstring
+    secure_auth*: my_bool     # Refuse client connecting to server if it uses old (pre-4.1.1) protocol
+    report_data_truncation*: my_bool # 0 - never report, 1 - always report (default)
+                                     # function pointers for local infile support  
+    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
+
+  mysql_status* = enum 
+    MYSQL_STATUS_READY, MYSQL_STATUS_GET_RESULT, MYSQL_STATUS_USE_RESULT
+  mysql_protocol_type* = enum  # There are three types of queries - the ones that have to go to
+                               #      the master, the ones that go to a slave, and the adminstrative
+                               #      type which must happen on the pivot connectioin 
+    MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET, 
+    MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
+  mysql_rpl_type* = enum 
+    MYSQL_RPL_MASTER, MYSQL_RPL_SLAVE, MYSQL_RPL_ADMIN
+  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    # was ^MY_UNI_IDX
+    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            # was ^MY_CHARSET_HANDLER
+    coll*: pointer            # was ^MY_COLLATION_HANDLER;
+  
+  CHARSET_INFO* = charset_info_st
+  Pcharset_info_st* = ptr charset_info_st
+  Pcharacter_set* = ptr character_set
+  character_set*{.final.} = object 
+    number*: cuint
+    state*: cuint
+    csname*: cstring
+    name*: cstring
+    comment*: cstring
+    dir*: cstring
+    mbminlen*: cuint
+    mbmaxlen*: cuint
+
+  MY_CHARSET_INFO* = character_set
+  PMY_CHARSET_INFO* = ptr MY_CHARSET_INFO
+  Pst_mysql_methods* = ptr st_mysql_methods
+  Pst_mysql* = ptr st_mysql
+  st_mysql*{.final.} = object 
+    net*: NET                 # Communication parameters
+    connector_fd*: gptr       # ConnectorFd for SSL
+    host*: cstring
+    user*: cstring
+    passwd*: cstring
+    unix_socket*: cstring
+    server_version*: cstring
+    host_info*: cstring
+    info*: cstring
+    db*: cstring
+    charset*: Pcharset_info_st
+    fields*: PMYSQL_FIELD
+    field_alloc*: MEM_ROOT
+    affected_rows*: my_ulonglong
+    insert_id*: my_ulonglong  # id if insert on table with NEXTNR
+    extra_info*: my_ulonglong # Used by mysqlshow, not used by mysql 5.0 and up
+    thread_id*: int        # Id for connection in server
+    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*: mysql_status
+    free_me*: my_bool         # If free in mysql_close
+    reconnect*: my_bool       # set to 1 if automatic reconnect
+    scramble*: array[0..(SCRAMBLE_LENGTH + 1) - 1, char] # session-wide random string
+                                                         #  Set if this is the original connection, not a master or a slave we have
+                                                         #       added though mysql_rpl_probe() or mysql_set_master()/ mysql_add_slave()      
+    rpl_pivot*: my_bool #   Pointers to the master, and the next slave connections, points to
+                        #        itself if lone connection.       
+    master*: Pst_mysql
+    next_slave*: Pst_mysql
+    last_used_slave*: Pst_mysql # needed for round-robin slave pick
+    last_used_con*: Pst_mysql # needed for send/read/store/use result to work correctly with replication
+    stmts*: Pointer           # was PList, list of all statements
+    methods*: Pst_mysql_methods
+    thd*: pointer #   Points to boolean flag in MYSQL_RES  or MYSQL_STMT. We set this flag
+                  #        from mysql_stmt_close if close had to cancel result set of this object.       
+    unbuffered_fetch_owner*: Pmy_bool
+
+  MYSQL* = st_mysql
+  PMYSQL* = ptr MYSQL
+  Pst_mysql_res* = ptr st_mysql_res
+  st_mysql_res*{.final.} = object 
+    row_count*: my_ulonglong
+    fields*: PMYSQL_FIELD
+    data*: PMYSQL_DATA
+    data_cursor*: PMYSQL_ROWS
+    lengths*: ptr int         # column lengths of current row
+    handle*: PMYSQL           # for unbuffered reads
+    field_alloc*: MEM_ROOT
+    field_count*: cuint
+    current_field*: cuint
+    row*: MYSQL_ROW           # If unbuffered read
+    current_row*: MYSQL_ROW   # buffer to current row
+    eof*: my_bool             # Used by mysql_fetch_row
+    unbuffered_fetch_cancelled*: my_bool # mysql_stmt_close() had to cancel this result
+    methods*: Pst_mysql_methods
+
+  MYSQL_RES* = st_mysql_res
+  PMYSQL_RES* = ptr MYSQL_RES
+  Pst_mysql_stmt* = ptr st_mysql_stmt
+  PMYSQL_STMT* = ptr MYSQL_STMT
+  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, mysql_fields: PMYSQL_FIELD, fields: cuint): PMYSQL_DATA
+    use_result*: proc (mysql: PMYSQL): PMYSQL_RES
+    fetch_lengths*: proc (fto: ptr int, column: MYSQL_ROW, field_count: cuint)
+    flush_use_result*: proc (mysql: PMYSQL)
+    list_fields*: proc (mysql: PMYSQL): PMYSQL_FIELD
+    read_prepare_result*: proc (mysql: PMYSQL, stmt: PMYSQL_STMT): my_bool
+    stmt_execute*: proc (stmt: PMYSQL_STMT): cint
+    read_binary_rows*: proc (stmt: PMYSQL_STMT): 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: PMYSQL_STMT): cint
+
+  MYSQL_METHODS* = st_mysql_methods
+  PMYSQL_METHODS* = ptr MYSQL_METHODS
+  Pst_mysql_manager* = ptr st_mysql_manager
+  st_mysql_manager*{.final.} = object 
+    net*: NET
+    host*: cstring
+    user*: cstring
+    passwd*: cstring
+    port*: cuint
+    free_me*: my_bool
+    eof*: my_bool
+    cmd_status*: cint
+    last_errno*: cint
+    net_buf*: cstring
+    net_buf_pos*: cstring
+    net_data_end*: cstring
+    net_buf_size*: cint
+    last_error*: array[0..(MAX_MYSQL_MANAGER_ERR) - 1, char]
+
+  MYSQL_MANAGER* = st_mysql_manager
+  PMYSQL_MANAGER* = ptr MYSQL_MANAGER
+  Pst_mysql_parameters* = ptr st_mysql_parameters
+  st_mysql_parameters*{.final.} = object 
+    p_max_allowed_packet*: ptr int
+    p_net_buffer_length*: ptr int
+
+  MYSQL_PARAMETERS* = st_mysql_parameters
+  PMYSQL_PARAMETERS* = ptr MYSQL_PARAMETERS
+  enum_mysql_stmt_state* = enum     
+    MYSQL_STMT_INIT_DONE = 1, MYSQL_STMT_PREPARE_DONE, MYSQL_STMT_EXECUTE_DONE, 
+    MYSQL_STMT_FETCH_DONE
+  Pst_mysql_bind* = ptr st_mysql_bind
+  st_mysql_bind*{.final.} = object 
+    len*: int              # output length pointer
+    is_null*: Pmy_bool        # Pointer to null indicator
+    buffer*: pointer          # buffer to get/put data
+    error*: pmy_bool          # set this if you want to track data truncations happened during fetch
+    buffer_type*: enum_field_types # buffer type
+    buffer_length*: int    # buffer length, must be set for str/binary
+                           # Following are for internal use. Set by mysql_stmt_bind_param  
+    row_ptr*: ptr byte        # for the current data position
+    offset*: int           # offset position for char/binary fetch
+    length_value*: int     #  Used if length is 0
+    param_number*: cuint      # For null count and error messages
+    pack_length*: cuint       # Internal length for packed data
+    error_value*: my_bool     # used if error is 0
+    is_unsigned*: my_bool     # set if integer type is unsigned
+    long_data_used*: my_bool  # If used with mysql_send_long_data
+    is_null_value*: my_bool   # Used if is_null is 0
+    store_param_func*: proc (net: PNET, param: Pst_mysql_bind){.cdecl.}
+    fetch_result*: proc (para1: Pst_mysql_bind, para2: PMYSQL_FIELD, row: PPbyte)
+    skip_result*: proc (para1: Pst_mysql_bind, para2: PMYSQL_FIELD, row: PPbyte)
+
+  MYSQL_BIND* = st_mysql_bind
+  PMYSQL_BIND* = ptr MYSQL_BIND # statement handler  
+  st_mysql_stmt*{.final.} = object 
+    mem_root*: MEM_ROOT       # root allocations
+    mysql*: PMYSQL            # connection handle
+    params*: PMYSQL_BIND      # input parameters
+    bind*: PMYSQL_BIND        # input parameters
+    fields*: PMYSQL_FIELD     # result set metadata
+    result*: MYSQL_DATA       # cached result set
+    data_cursor*: PMYSQL_ROWS # current row in cached result
+    affected_rows*: my_ulonglong # copy of mysql->affected_rows after statement execution
+    insert_id*: my_ulonglong 
+    read_row_func*: proc (stmt: Pst_mysql_stmt, row: PPbyte): cint{.cdecl.}
+    stmt_id*: int          # Id for prepared statement
+    flags*: int            # i.e. type of cursor to open
+    prefetch_rows*: int    # number of rows per one COM_FETCH
+    server_status*: cuint # Copied from mysql->server_status after execute/fetch to know
+                          # server-side cursor status for this statement.
+    last_errno*: cuint        # error code
+    param_count*: cuint       # input parameter count
+    field_count*: cuint       # number of columns in result set
+    state*: enum_mysql_stmt_state # statement state
+    last_error*: array[0..(MYSQL_ERRMSG_SIZE) - 1, char] # error message
+    sqlstate*: array[0..(SQLSTATE_LENGTH + 1) - 1, char]
+    send_types_to_server*: my_bool # Types of input parameters should be sent to server
+    bind_param_done*: my_bool # input buffers were supplied
+    bind_result_done*: char # output buffers were supplied
+    unbuffered_fetch_cancelled*: my_bool        
+    update_max_length*: my_bool
+
+  MYSQL_STMT* = st_mysql_stmt # When doing mysql_stmt_store_result calculate max_length attribute
+                              # of statement metadata. This is to be consistent with the old API,
+                              # where this was done automatically.
+                              # In the new API we do that only by request because it slows down
+                              # mysql_stmt_store_result sufficiently.       
+  enum_stmt_attr_type* = enum
+    STMT_ATTR_UPDATE_MAX_LENGTH, STMT_ATTR_CURSOR_TYPE,  
+    STMT_ATTR_PREFETCH_ROWS 
+    
+proc mysql_server_init*(argc: cint, argv: cstringArray, groups: cstringArray): cint{.cdecl, 
+    dynlib: mysqllib, importc: "mysql_server_init".}
+proc mysql_server_end*(){.cdecl, dynlib: mysqllib, importc: "mysql_server_end".}
+  # mysql_server_init/end need to be called when using libmysqld or
+  #      libmysqlclient (exactly, mysql_server_init() is called by mysql_init() so
+  #      you don't need to call it explicitely; but you need to call
+  #      mysql_server_end() to free memory). The names are a bit misleading
+  #      (mysql_SERVER* to be used when using libmysqlCLIENT). So we add more general
+  #      names which suit well whether you're using libmysqld or libmysqlclient. We
+  #      intend to promote these aliases over the mysql_server* ones.     
+proc mysql_library_init*(argc: cint, argv: cstringArray, groups: cstringArray): cint{.cdecl, 
+    dynlib: mysqllib, importc: "mysql_server_init".}
+proc mysql_library_end*(){.cdecl, dynlib: mysqllib, importc: "mysql_server_end".}
+proc mysql_get_parameters*(): PMYSQL_PARAMETERS{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_get_parameters".}
+  # Set up and bring down a thread; these function should be called
+  #      for each thread in an application which opens at least one MySQL
+  #      connection.  All uses of the connection(s) should be between these
+  #      function calls.     
+proc mysql_thread_init*(): my_bool{.stdcall, dynlib: mysqllib, 
+                                    importc: "mysql_thread_init".}
+proc mysql_thread_end*(){.stdcall, dynlib: mysqllib, importc: "mysql_thread_end".}
+  # Functions to get information from the MYSQL and MYSQL_RES structures
+  #      Should definitely be used if one uses shared libraries.     
+proc mysql_num_rows*(res: PMYSQL_RES): my_ulonglong{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_num_rows".}
+proc mysql_num_fields*(res: PMYSQL_RES): cuint{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_num_fields".}
+proc mysql_eof*(res: PMYSQL_RES): my_bool{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_eof".}
+proc mysql_fetch_field_direct*(res: PMYSQL_RES, fieldnr: cuint): PMYSQL_FIELD{.
+    stdcall, dynlib: mysqllib, importc: "mysql_fetch_field_direct".}
+proc mysql_fetch_fields*(res: PMYSQL_RES): PMYSQL_FIELD{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_fetch_fields".}
+proc mysql_row_tell*(res: PMYSQL_RES): MYSQL_ROW_OFFSET{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_row_tell".}
+proc mysql_field_tell*(res: PMYSQL_RES): MYSQL_FIELD_OFFSET{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_field_tell".}
+proc mysql_field_count*(mysql: PMYSQL): cuint{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_field_count".}
+proc mysql_affected_rows*(mysql: PMYSQL): my_ulonglong{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_affected_rows".}
+proc mysql_insert_id*(mysql: PMYSQL): my_ulonglong{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_insert_id".}
+proc mysql_errno*(mysql: PMYSQL): cuint{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_errno".}
+proc mysql_error*(mysql: PMYSQL): cstring{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_error".}
+proc mysql_sqlstate*(mysql: PMYSQL): cstring{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_sqlstate".}
+proc mysql_warning_count*(mysql: PMYSQL): cuint{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_warning_count".}
+proc mysql_info*(mysql: PMYSQL): cstring{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_info".}
+proc mysql_thread_id*(mysql: PMYSQL): int{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_thread_id".}
+proc mysql_character_set_name*(mysql: PMYSQL): cstring{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_character_set_name".}
+proc mysql_set_character_set*(mysql: PMYSQL, csname: cstring): int32{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_set_character_set".}
+proc mysql_init*(mysql: PMYSQL): PMYSQL{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_init".}
+proc mysql_ssl_set*(mysql: PMYSQL, key: cstring, cert: cstring, ca: cstring, 
+                    capath: cstring, cipher: cstring): my_bool{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_ssl_set".}
+proc mysql_change_user*(mysql: PMYSQL, user: cstring, passwd: cstring, 
+                        db: cstring): my_bool{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_change_user".}
+proc mysql_real_connect*(mysql: PMYSQL, host: cstring, user: cstring, 
+                         passwd: cstring, db: cstring, port: cuint, 
+                         unix_socket: cstring, clientflag: int): PMYSQL{.
+    stdcall, dynlib: mysqllib, importc: "mysql_real_connect".}
+proc mysql_select_db*(mysql: PMYSQL, db: cstring): cint{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_select_db".}
+proc mysql_query*(mysql: PMYSQL, q: cstring): cint{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_query".}
+proc mysql_send_query*(mysql: PMYSQL, q: cstring, len: int): cint{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_send_query".}
+proc mysql_real_query*(mysql: PMYSQL, q: cstring, len: int): cint{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_real_query".}
+proc mysql_store_result*(mysql: PMYSQL): PMYSQL_RES{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_store_result".}
+proc mysql_use_result*(mysql: PMYSQL): PMYSQL_RES{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_use_result".}
+  # perform query on master  
+proc mysql_master_query*(mysql: PMYSQL, q: cstring, len: int): my_bool{.
+    stdcall, dynlib: mysqllib, importc: "mysql_master_query".}
+proc mysql_master_send_query*(mysql: PMYSQL, q: cstring, len: int): my_bool{.
+    stdcall, dynlib: mysqllib, importc: "mysql_master_send_query".}
+  # perform query on slave  
+proc mysql_slave_query*(mysql: PMYSQL, q: cstring, len: int): my_bool{.
+    stdcall, dynlib: mysqllib, importc: "mysql_slave_query".}
+proc mysql_slave_send_query*(mysql: PMYSQL, q: cstring, len: int): my_bool{.
+    stdcall, dynlib: mysqllib, importc: "mysql_slave_send_query".}
+proc mysql_get_character_set_info*(mysql: PMYSQL, charset: PMY_CHARSET_INFO){.
+    stdcall, dynlib: mysqllib, importc: "mysql_get_character_set_info".}
+  # local infile support  
+const 
+  LOCAL_INFILE_ERROR_LEN* = 512 
+  
+# 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
+# para6:pointer);cdecl;external mysqllib name 'mysql_set_local_infile_handler';
+
+proc mysql_set_local_infile_default*(mysql: PMYSQL){.cdecl, dynlib: mysqllib, 
+    importc: "mysql_set_local_infile_default".}
+  # enable/disable parsing of all queries to decide if they go on master or
+  #      slave     
+proc mysql_enable_rpl_parse*(mysql: PMYSQL){.stdcall, dynlib: mysqllib, 
+    importc: "mysql_enable_rpl_parse".}
+proc mysql_disable_rpl_parse*(mysql: PMYSQL){.stdcall, dynlib: mysqllib, 
+    importc: "mysql_disable_rpl_parse".}
+  # get the value of the parse flag  
+proc mysql_rpl_parse_enabled*(mysql: PMYSQL): cint{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_rpl_parse_enabled".}
+  #  enable/disable reads from master  
+proc mysql_enable_reads_from_master*(mysql: PMYSQL){.stdcall, dynlib: mysqllib, 
+    importc: "mysql_enable_reads_from_master".}
+proc mysql_disable_reads_from_master*(mysql: PMYSQL){.stdcall, dynlib: mysqllib, 
+    importc: "mysql_disable_reads_from_master".}
+  # get the value of the master read flag  
+proc mysql_reads_from_master_enabled*(mysql: PMYSQL): my_bool{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_reads_from_master_enabled".}
+proc mysql_rpl_query_type*(q: cstring, length: cint): mysql_rpl_type{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_rpl_query_type".}
+  # discover the master and its slaves  
+proc mysql_rpl_probe*(mysql: PMYSQL): my_bool{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_rpl_probe".}
+  # set the master, close/free the old one, if it is not a pivot  
+proc mysql_set_master*(mysql: PMYSQL, host: cstring, port: cuint, user: cstring, 
+                       passwd: cstring): cint{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_set_master".}
+proc mysql_add_slave*(mysql: PMYSQL, host: cstring, port: cuint, user: cstring, 
+                      passwd: cstring): cint{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_add_slave".}
+proc mysql_shutdown*(mysql: PMYSQL, shutdown_level: mysql_enum_shutdown_level): cint{.
+    stdcall, dynlib: mysqllib, importc: "mysql_shutdown".}
+proc mysql_dump_debug_info*(mysql: PMYSQL): cint{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_dump_debug_info".}
+proc mysql_refresh*(mysql: PMYSQL, refresh_options: cuint): cint{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_refresh".}
+proc mysql_kill*(mysql: PMYSQL, pid: int): cint{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_kill".}
+proc mysql_set_server_option*(mysql: PMYSQL, option: enum_mysql_set_option): cint{.
+    stdcall, dynlib: mysqllib, importc: "mysql_set_server_option".}
+proc mysql_ping*(mysql: PMYSQL): cint{.stdcall, dynlib: mysqllib, 
+                                       importc: "mysql_ping".}
+proc mysql_stat*(mysql: PMYSQL): cstring{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_stat".}
+proc mysql_get_server_info*(mysql: PMYSQL): cstring{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_get_server_info".}
+proc mysql_get_client_info*(): cstring{.stdcall, dynlib: mysqllib, 
+                                        importc: "mysql_get_client_info".}
+proc mysql_get_client_version*(): int{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_get_client_version".}
+proc mysql_get_host_info*(mysql: PMYSQL): cstring{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_get_host_info".}
+proc mysql_get_server_version*(mysql: PMYSQL): int{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_get_server_version".}
+proc mysql_get_proto_info*(mysql: PMYSQL): cuint{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_get_proto_info".}
+proc mysql_list_dbs*(mysql: PMYSQL, wild: cstring): PMYSQL_RES{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_list_dbs".}
+proc mysql_list_tables*(mysql: PMYSQL, wild: cstring): PMYSQL_RES{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_list_tables".}
+proc mysql_list_processes*(mysql: PMYSQL): PMYSQL_RES{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_list_processes".}
+proc mysql_options*(mysql: PMYSQL, option: mysql_option, arg: cstring): cint{.
+    stdcall, dynlib: mysqllib, importc: "mysql_options".}
+proc mysql_free_result*(result: PMYSQL_RES){.stdcall, dynlib: mysqllib, 
+    importc: "mysql_free_result".}
+proc mysql_data_seek*(result: PMYSQL_RES, offset: my_ulonglong){.stdcall, 
+    dynlib: mysqllib, importc: "mysql_data_seek".}
+proc mysql_row_seek*(result: PMYSQL_RES, offset: MYSQL_ROW_OFFSET): MYSQL_ROW_OFFSET{.
+    stdcall, dynlib: mysqllib, importc: "mysql_row_seek".}
+proc mysql_field_seek*(result: PMYSQL_RES, offset: MYSQL_FIELD_OFFSET): MYSQL_FIELD_OFFSET{.
+    stdcall, dynlib: mysqllib, importc: "mysql_field_seek".}
+proc mysql_fetch_row*(result: PMYSQL_RES): MYSQL_ROW{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_fetch_row".}
+proc mysql_fetch_lengths*(result: PMYSQL_RES): ptr int{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_fetch_lengths".}
+proc mysql_fetch_field*(result: PMYSQL_RES): PMYSQL_FIELD{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_fetch_field".}
+proc mysql_list_fields*(mysql: PMYSQL, table: cstring, wild: cstring): PMYSQL_RES{.
+    stdcall, dynlib: mysqllib, importc: "mysql_list_fields".}
+proc mysql_escape_string*(fto: cstring, `from`: cstring, from_length: int): int{.
+    stdcall, dynlib: mysqllib, importc: "mysql_escape_string".}
+proc mysql_hex_string*(fto: cstring, `from`: cstring, from_length: int): int{.
+    stdcall, dynlib: mysqllib, importc: "mysql_hex_string".}
+proc mysql_real_escape_string*(mysql: PMYSQL, fto: cstring, `from`: cstring, 
+                               len: int): int{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_real_escape_string".}
+proc mysql_debug*(debug: cstring){.stdcall, dynlib: mysqllib, 
+                                   importc: "mysql_debug".}
+  #    function mysql_odbc_escape_string(mysql:PMYSQL; fto:Pchar; to_length:dword; from:Pchar; from_length:dword;
+  #               param:pointer; extend_buffer:function (para1:pointer; to:Pchar; length:Pdword):Pchar):Pchar;stdcall;external mysqllib name 'mysql_odbc_escape_string';
+proc myodbc_remove_escape*(mysql: PMYSQL, name: cstring){.stdcall, 
+    dynlib: mysqllib, importc: "myodbc_remove_escape".}
+proc mysql_thread_safe*(): cuint{.stdcall, dynlib: mysqllib, 
+                                  importc: "mysql_thread_safe".}
+proc mysql_embedded*(): my_bool{.stdcall, dynlib: mysqllib, 
+                                 importc: "mysql_embedded".}
+proc mysql_manager_init*(con: PMYSQL_MANAGER): PMYSQL_MANAGER{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_manager_init".}
+proc mysql_manager_connect*(con: PMYSQL_MANAGER, host: cstring, user: cstring, 
+                            passwd: cstring, port: cuint): PMYSQL_MANAGER{.
+    stdcall, dynlib: mysqllib, importc: "mysql_manager_connect".}
+proc mysql_manager_close*(con: PMYSQL_MANAGER){.stdcall, dynlib: mysqllib, 
+    importc: "mysql_manager_close".}
+proc mysql_manager_command*(con: PMYSQL_MANAGER, cmd: cstring, cmd_len: cint): cint{.
+    stdcall, dynlib: mysqllib, importc: "mysql_manager_command".}
+proc mysql_manager_fetch_line*(con: PMYSQL_MANAGER, res_buf: cstring, 
+                               res_buf_size: cint): cint{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_manager_fetch_line".}
+proc mysql_read_query_result*(mysql: PMYSQL): my_bool{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_read_query_result".}
+proc mysql_stmt_init*(mysql: PMYSQL): PMYSQL_STMT{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_stmt_init".}
+proc mysql_stmt_prepare*(stmt: PMYSQL_STMT, query: cstring, len: int): cint{.
+    stdcall, dynlib: mysqllib, importc: "mysql_stmt_prepare".}
+proc mysql_stmt_execute*(stmt: PMYSQL_STMT): cint{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_stmt_execute".}
+proc mysql_stmt_fetch*(stmt: PMYSQL_STMT): cint{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_stmt_fetch".}
+proc mysql_stmt_fetch_column*(stmt: PMYSQL_STMT, bind: PMYSQL_BIND, 
+                              column: cuint, offset: int): cint{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_stmt_fetch_column".}
+proc mysql_stmt_store_result*(stmt: PMYSQL_STMT): cint{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_stmt_store_result".}
+proc mysql_stmt_param_count*(stmt: PMYSQL_STMT): int{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_stmt_param_count".}
+proc mysql_stmt_attr_set*(stmt: PMYSQL_STMT, attr_type: enum_stmt_attr_type, 
+                          attr: pointer): my_bool{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_stmt_attr_set".}
+proc mysql_stmt_attr_get*(stmt: PMYSQL_STMT, attr_type: enum_stmt_attr_type, 
+                          attr: pointer): my_bool{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_stmt_attr_get".}
+proc mysql_stmt_bind_param*(stmt: PMYSQL_STMT, bnd: PMYSQL_BIND): my_bool{.
+    stdcall, dynlib: mysqllib, importc: "mysql_stmt_bind_param".}
+proc mysql_stmt_bind_result*(stmt: PMYSQL_STMT, bnd: PMYSQL_BIND): my_bool{.
+    stdcall, dynlib: mysqllib, importc: "mysql_stmt_bind_result".}
+proc mysql_stmt_close*(stmt: PMYSQL_STMT): my_bool{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_stmt_close".}
+proc mysql_stmt_reset*(stmt: PMYSQL_STMT): my_bool{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_stmt_reset".}
+proc mysql_stmt_free_result*(stmt: PMYSQL_STMT): my_bool{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_stmt_free_result".}
+proc mysql_stmt_send_long_data*(stmt: PMYSQL_STMT, param_number: cuint, 
+                                data: cstring, len: int): my_bool{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_stmt_send_long_data".}
+proc mysql_stmt_result_metadata*(stmt: PMYSQL_STMT): PMYSQL_RES{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_stmt_result_metadata".}
+proc mysql_stmt_param_metadata*(stmt: PMYSQL_STMT): PMYSQL_RES{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_stmt_param_metadata".}
+proc mysql_stmt_errno*(stmt: PMYSQL_STMT): cuint{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_stmt_errno".}
+proc mysql_stmt_error*(stmt: PMYSQL_STMT): cstring{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_stmt_error".}
+proc mysql_stmt_sqlstate*(stmt: PMYSQL_STMT): cstring{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_stmt_sqlstate".}
+proc mysql_stmt_row_seek*(stmt: PMYSQL_STMT, offset: MYSQL_ROW_OFFSET): MYSQL_ROW_OFFSET{.
+    stdcall, dynlib: mysqllib, importc: "mysql_stmt_row_seek".}
+proc mysql_stmt_row_tell*(stmt: PMYSQL_STMT): MYSQL_ROW_OFFSET{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_stmt_row_tell".}
+proc mysql_stmt_data_seek*(stmt: PMYSQL_STMT, offset: my_ulonglong){.stdcall, 
+    dynlib: mysqllib, importc: "mysql_stmt_data_seek".}
+proc mysql_stmt_num_rows*(stmt: PMYSQL_STMT): my_ulonglong{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_stmt_num_rows".}
+proc mysql_stmt_affected_rows*(stmt: PMYSQL_STMT): my_ulonglong{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_stmt_affected_rows".}
+proc mysql_stmt_insert_id*(stmt: PMYSQL_STMT): my_ulonglong{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_stmt_insert_id".}
+proc mysql_stmt_field_count*(stmt: PMYSQL_STMT): cuint{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_stmt_field_count".}
+proc mysql_commit*(mysql: PMYSQL): my_bool{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_commit".}
+proc mysql_rollback*(mysql: PMYSQL): my_bool{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_rollback".}
+proc mysql_autocommit*(mysql: PMYSQL, auto_mode: my_bool): my_bool{.stdcall, 
+    dynlib: mysqllib, importc: "mysql_autocommit".}
+proc mysql_more_results*(mysql: PMYSQL): my_bool{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_more_results".}
+proc mysql_next_result*(mysql: PMYSQL): cint{.stdcall, dynlib: mysqllib, 
+    importc: "mysql_next_result".}
+proc mysql_close*(sock: PMYSQL){.stdcall, dynlib: mysqllib, 
+                                 importc: "mysql_close".}
+  # status return codes  
+const 
+  MYSQL_NO_DATA* = 100
+  MYSQL_DATA_TRUNCATED* = 101
+
+proc mysql_reload*(mysql: PMySQL): cint
+
+when defined(USE_OLD_FUNCTIONS): 
+  proc mysql_connect*(mysql: PMYSQL, host: cstring, user: cstring, 
+                      passwd: cstring): PMYSQL{.stdcall, 
+      dynlib: External_library, importc: "mysql_connect".}
+  proc mysql_create_db*(mysql: PMYSQL, DB: cstring): cint{.stdcall, 
+      dynlib: External_library, importc: "mysql_create_db".}
+  proc mysql_drop_db*(mysql: PMYSQL, DB: cstring): cint{.stdcall, 
+      dynlib: External_library, importc: "mysql_drop_db".}
+  proc mysql_reload*(mysql: PMySQL): cint
+
+proc net_safe_read*(mysql: PMYSQL): cuint{.cdecl, dynlib: mysqllib, 
+    importc: "net_safe_read".}
+
+proc net_new_transaction(net: st_net): st_net = 
+  assert false
+  #net.pkt_nr = 0
+  result = net
+
+proc IS_PRI_KEY(n: int32): bool = 
+  result = (n and PRI_KEY_FLAG) != 0
+
+proc IS_NOT_NULL(n: int32): bool = 
+  result = (n and NOT_NULL_FLAG) != 0
+
+proc IS_BLOB(n: int32): bool = 
+  result = (n and BLOB_FLAG) != 0
+
+proc IS_NUM_FIELD(f: pst_mysql_field): bool = 
+  result = (f.flags and NUM_FLAG) != 0
+
+proc IS_NUM(t: enum_field_types): bool = 
+  result = (t <= FIELD_TYPE_INT24) or (t == FIELD_TYPE_YEAR) or
+      (t == FIELD_TYPE_NEWDECIMAL)
+
+proc INTERNAL_NUM_FIELD(f: Pst_mysql_field): bool = 
+  result = (f.ftype <= FIELD_TYPE_INT24) and
+      ((f.ftype != FIELD_TYPE_TIMESTAMP) or (f.len == 14) or (f.len == 8)) or
+      (f.ftype == FIELD_TYPE_YEAR)
+
+proc mysql_reload(mysql: PMySQL): cint = 
+  result = mysql_refresh(mysql, REFRESH_GRANT)
+
diff --git a/lib/base/sqlite3.nim b/lib/base/sqlite3.nim
new file mode 100644
index 000000000..9a97330ec
--- /dev/null
+++ b/lib/base/sqlite3.nim
@@ -0,0 +1,376 @@
+#
+#
+#            Nimrod's Runtime Library
+#        (c) Copyright 2009 Andreas Rumpf
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+{.deadCodeElim: on.}
+
+when defined(windows): 
+  const Sqlite3Lib = "sqlite3.dll"
+elif defined(macosx):
+  const Sqlite3Lib = "sqlite-3.6.13.dylib"
+else: 
+  const Sqlite3Lib = "libsqlite3.so"
+
+const 
+  SQLITE_INTEGER* = 1
+  SQLITE_FLOAT* = 2
+  SQLITE_BLOB* = 4
+  SQLITE_NULL* = 5
+  SQLITE_TEXT* = 3
+  SQLITE3_TEXT* = 3
+  SQLITE_UTF8* = 1
+  SQLITE_UTF16LE* = 2
+  SQLITE_UTF16BE* = 3         # Use native byte order  
+  SQLITE_UTF16* = 4           # sqlite3_create_function only  
+  SQLITE_ANY* = 5             #sqlite_exec return values
+  SQLITE_OK* = 0
+  SQLITE_ERROR* = 1           # SQL error or missing database  
+  SQLITE_INTERNAL* = 2        # An internal logic error in SQLite  
+  SQLITE_PERM* = 3            # Access permission denied  
+  SQLITE_ABORT* = 4           # Callback routine requested an abort  
+  SQLITE_BUSY* = 5            # The database file is locked  
+  SQLITE_LOCKED* = 6          # A table in the database is locked  
+  SQLITE_NOMEM* = 7           # A malloc() failed  
+  SQLITE_READONLY* = 8        # Attempt to write a readonly database  
+  SQLITE_INTERRUPT* = 9       # Operation terminated by sqlite3_interrupt() 
+  SQLITE_IOERR* = 10          # Some kind of disk I/O error occurred  
+  SQLITE_CORRUPT* = 11        # The database disk image is malformed  
+  SQLITE_NOTFOUND* = 12       # (Internal Only) Table or record not found  
+  SQLITE_FULL* = 13           # Insertion failed because database is full  
+  SQLITE_CANTOPEN* = 14       # Unable to open the database file  
+  SQLITE_PROTOCOL* = 15       # Database lock protocol error  
+  SQLITE_EMPTY* = 16          # Database is empty  
+  SQLITE_SCHEMA* = 17         # The database schema changed  
+  SQLITE_TOOBIG* = 18         # Too much data for one row of a table  
+  SQLITE_CONSTRAINT* = 19     # Abort due to contraint violation  
+  SQLITE_MISMATCH* = 20       # Data type mismatch  
+  SQLITE_MISUSE* = 21         # Library used incorrectly  
+  SQLITE_NOLFS* = 22          # Uses OS features not supported on host  
+  SQLITE_AUTH* = 23           # Authorization denied  
+  SQLITE_FORMAT* = 24         # Auxiliary database format error  
+  SQLITE_RANGE* = 25          # 2nd parameter to sqlite3_bind out of range  
+  SQLITE_NOTADB* = 26         # File opened that is not a database file  
+  SQLITE_ROW* = 100           # sqlite3_step() has another row ready  
+  SQLITE_DONE* = 101          # sqlite3_step() has finished executing  
+  SQLITE_COPY* = 0
+  SQLITE_CREATE_INDEX* = 1
+  SQLITE_CREATE_TABLE* = 2
+  SQLITE_CREATE_TEMP_INDEX* = 3
+  SQLITE_CREATE_TEMP_TABLE* = 4
+  SQLITE_CREATE_TEMP_TRIGGER* = 5
+  SQLITE_CREATE_TEMP_VIEW* = 6
+  SQLITE_CREATE_TRIGGER* = 7
+  SQLITE_CREATE_VIEW* = 8
+  SQLITE_DELETE* = 9
+  SQLITE_DROP_INDEX* = 10
+  SQLITE_DROP_TABLE* = 11
+  SQLITE_DROP_TEMP_INDEX* = 12
+  SQLITE_DROP_TEMP_TABLE* = 13
+  SQLITE_DROP_TEMP_TRIGGER* = 14
+  SQLITE_DROP_TEMP_VIEW* = 15
+  SQLITE_DROP_TRIGGER* = 16
+  SQLITE_DROP_VIEW* = 17
+  SQLITE_INSERT* = 18
+  SQLITE_PRAGMA* = 19
+  SQLITE_READ* = 20
+  SQLITE_SELECT* = 21
+  SQLITE_TRANSACTION* = 22
+  SQLITE_UPDATE* = 23
+  SQLITE_ATTACH* = 24
+  SQLITE_DETACH* = 25
+  SQLITE_ALTER_TABLE* = 26
+  SQLITE_REINDEX* = 27
+  SQLITE_DENY* = 1
+  SQLITE_IGNORE* = 2          # Original from sqlite3.h: 
+                              ##define SQLITE_STATIC      ((void(*)(void *))0)
+                              ##define SQLITE_TRANSIENT   ((void(*)(void *))-1)
+
+const 
+  SQLITE_STATIC* = nil
+  SQLITE_TRANSIENT* = cast[pointer](-1)
+
+type 
+  sqlite_int64* = int64
+  PPPChar* = ptr ptr cstring
+  TSqlite3 {.pure, final.} = object
+  Psqlite3* = ptr TSqlite3
+  PPSqlite3* = ptr PSqlite3
+  TSqlLite3Context {.pure, final.} = object
+  Psqlite3_context* = ptr TSqlLite3Context
+  Tsqlite3_stmt {.pure, final.} = object
+  Psqlite3_stmt* = ptr TSqlite3_stmt
+  PPsqlite3_stmt* = ptr Psqlite3_stmt
+  Tsqlite3_value {.pure, final.} = object
+  Psqlite3_value* = ptr Tsqlite3_value
+  PPsqlite3_value* = ptr Psqlite3_value #Callback function types
+                                        #Notice that most functions 
+                                        #were named using as prefix the 
+                                        #function name that uses them,
+                                        #rather than describing their functions  
+  Tsqlite3_callback* = proc (para1: pointer, para2: int32, para3: var cstring, 
+                             para4: var cstring): int32{.cdecl.}
+  Tbind_destructor_func* = proc (para1: pointer){.cdecl.}
+  Tcreate_function_step_func* = proc (para1: Psqlite3_context, para2: int32, 
+                                     para3: PPsqlite3_value){.cdecl.}
+  Tcreate_function_func_func* = proc (para1: Psqlite3_context, para2: int32, 
+                                     para3: PPsqlite3_value){.cdecl.}
+  Tcreate_function_final_func* = proc (para1: Psqlite3_context){.cdecl.}
+  Tsqlite3_result_func* = proc (para1: pointer){.cdecl.}
+  Tsqlite3_create_collation_func* = proc (para1: pointer, para2: int32, 
+      para3: pointer, para4: int32, para5: pointer): int32{.cdecl.}
+  Tsqlite3_collation_needed_func* = proc (para1: pointer, para2: Psqlite3, 
+      eTextRep: int32, para4: cstring){.cdecl.}
+
+proc sqlite3_close*(para1: Psqlite3): int32{.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_close".}
+proc sqlite3_exec*(para1: Psqlite3, sql: cstring, para3: Tsqlite3_callback, 
+                   para4: pointer, errmsg: var cstring): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_exec".}
+proc sqlite3_last_insert_rowid*(para1: Psqlite3): sqlite_int64{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_last_insert_rowid".}
+proc sqlite3_changes*(para1: Psqlite3): int32{.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_changes".}
+proc sqlite3_total_changes*(para1: Psqlite3): int32{.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_total_changes".}
+proc sqlite3_interrupt*(para1: Psqlite3){.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_interrupt".}
+proc sqlite3_complete*(sql: cstring): int32{.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_complete".}
+proc sqlite3_complete16*(sql: pointer): int32{.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_complete16".}
+proc sqlite3_busy_handler*(para1: Psqlite3, 
+    para2: proc (para1: pointer, para2: int32): int32 {.cdecl.}, 
+    para3: pointer): int32{.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_busy_handler".}
+proc sqlite3_busy_timeout*(para1: Psqlite3, ms: int32): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_busy_timeout".}
+proc sqlite3_get_table*(para1: Psqlite3, sql: cstring, resultp: var cstringArray, 
+                        nrow, ncolumn: var cint, errmsg: ptr cstring): int32{.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_get_table".}
+proc sqlite3_free_table*(result: cstringArray){.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_free_table".}
+  # Todo: see how translate sqlite3_mprintf, sqlite3_vmprintf, sqlite3_snprintf
+  # function sqlite3_mprintf(_para1:Pchar; args:array of const):Pchar;cdecl; external Sqlite3Lib name 'sqlite3_mprintf';
+proc sqlite3_mprintf*(para1: cstring): cstring{.cdecl, varargs, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_mprintf".}
+  #function sqlite3_vmprintf(_para1:Pchar; _para2:va_list):Pchar;cdecl; external Sqlite3Lib name 'sqlite3_vmprintf';
+proc sqlite3_free*(z: cstring){.cdecl, dynlib: Sqlite3Lib, 
+                                importc: "sqlite3_free".}
+  #function sqlite3_snprintf(_para1:longint; _para2:Pchar; _para3:Pchar; args:array of const):Pchar;cdecl; external Sqlite3Lib name 'sqlite3_snprintf';
+proc sqlite3_snprintf*(para1: int32, para2: cstring, para3: cstring): cstring{.
+    cdecl, dynlib: Sqlite3Lib, varargs, importc: "sqlite3_snprintf".}
+proc sqlite3_set_authorizer*(para1: Psqlite3, 
+                             xAuth: proc (para1: pointer, para2: int32, 
+                                      para3: cstring, para4: cstring, 
+                                      para5: cstring, 
+                                      para6: cstring): int32{.cdecl.}, 
+                             pUserData: pointer): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_set_authorizer".}
+proc sqlite3_trace*(para1: Psqlite3, 
+                    xTrace: proc (para1: pointer, para2: cstring){.cdecl.}, 
+                    para3: pointer): pointer{.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_trace".}
+proc sqlite3_progress_handler*(para1: Psqlite3, para2: int32, 
+                               para3: proc (para1: pointer): int32 {.cdecl.}, 
+                               para4: pointer){.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_progress_handler".}
+proc sqlite3_commit_hook*(para1: Psqlite3, 
+                          para2: proc (para1: pointer): int32{.cdecl.}, 
+                          para3: pointer): pointer{.cdecl, dynlib: Sqlite3Lib,
+    importc: "sqlite3_commit_hook".}
+proc sqlite3_open*(filename: cstring, ppDb: var Psqlite3): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_open".}
+proc sqlite3_open16*(filename: pointer, ppDb: var Psqlite3): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_open16".}
+proc sqlite3_errcode*(db: Psqlite3): int32{.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_errcode".}
+proc sqlite3_errmsg*(para1: Psqlite3): cstring{.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_errmsg".}
+proc sqlite3_errmsg16*(para1: Psqlite3): pointer{.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_errmsg16".}
+proc sqlite3_prepare*(db: Psqlite3, zSql: cstring, nBytes: int32, 
+                      ppStmt: PPsqlite3_stmt, pzTail: ptr cstring): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_prepare".}
+proc sqlite3_prepare16*(db: Psqlite3, zSql: pointer, nBytes: int32, 
+                        ppStmt: PPsqlite3_stmt, pzTail: var pointer): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_prepare16".}
+proc sqlite3_bind_blob*(para1: Psqlite3_stmt, para2: int32, para3: pointer, 
+                        n: int32, para5: Tbind_destructor_func): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_bind_blob".}
+proc sqlite3_bind_double*(para1: Psqlite3_stmt, para2: int32, para3: float64): int32{.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_bind_double".}
+proc sqlite3_bind_int*(para1: Psqlite3_stmt, para2: int32, para3: int32): int32{.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_bind_int".}
+proc sqlite3_bind_int64*(para1: Psqlite3_stmt, para2: int32, para3: sqlite_int64): int32{.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_bind_int64".}
+proc sqlite3_bind_null*(para1: Psqlite3_stmt, para2: int32): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_bind_null".}
+proc sqlite3_bind_text*(para1: Psqlite3_stmt, para2: int32, para3: cstring, 
+                        n: int32, para5: Tbind_destructor_func): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_bind_text".}
+proc sqlite3_bind_text16*(para1: Psqlite3_stmt, para2: int32, para3: pointer, 
+                          para4: int32, para5: Tbind_destructor_func): int32{.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_bind_text16".}
+  #function sqlite3_bind_value(_para1:Psqlite3_stmt; _para2:longint; _para3:Psqlite3_value):longint;cdecl; external Sqlite3Lib name 'sqlite3_bind_value';
+  #These overloaded functions were introduced to allow the use of SQLITE_STATIC and SQLITE_TRANSIENT
+  #It's the c world man ;-)
+proc sqlite3_bind_blob*(para1: Psqlite3_stmt, para2: int32, para3: pointer, 
+                        n: int32, para5: int32): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_bind_blob".}
+proc sqlite3_bind_text*(para1: Psqlite3_stmt, para2: int32, para3: cstring, 
+                        n: int32, para5: int32): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_bind_text".}
+proc sqlite3_bind_text16*(para1: Psqlite3_stmt, para2: int32, para3: pointer, 
+                          para4: int32, para5: int32): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_bind_text16".}
+proc sqlite3_bind_parameter_count*(para1: Psqlite3_stmt): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_bind_parameter_count".}
+proc sqlite3_bind_parameter_name*(para1: Psqlite3_stmt, para2: int32): cstring{.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_bind_parameter_name".}
+proc sqlite3_bind_parameter_index*(para1: Psqlite3_stmt, zName: cstring): int32{.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_bind_parameter_index".}
+  #function sqlite3_clear_bindings(_para1:Psqlite3_stmt):longint;cdecl; external Sqlite3Lib name 'sqlite3_clear_bindings';
+proc sqlite3_column_count*(pStmt: Psqlite3_stmt): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_column_count".}
+proc sqlite3_column_name*(para1: Psqlite3_stmt, para2: int32): cstring{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_column_name".}
+proc sqlite3_column_name16*(para1: Psqlite3_stmt, para2: int32): pointer{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_column_name16".}
+proc sqlite3_column_decltype*(para1: Psqlite3_stmt, i: int32): cstring{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_column_decltype".}
+proc sqlite3_column_decltype16*(para1: Psqlite3_stmt, para2: int32): pointer{.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_column_decltype16".}
+proc sqlite3_step*(para1: Psqlite3_stmt): int32{.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_step".}
+proc sqlite3_data_count*(pStmt: Psqlite3_stmt): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_data_count".}
+proc sqlite3_column_blob*(para1: Psqlite3_stmt, iCol: int32): pointer{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_column_blob".}
+proc sqlite3_column_bytes*(para1: Psqlite3_stmt, iCol: int32): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_column_bytes".}
+proc sqlite3_column_bytes16*(para1: Psqlite3_stmt, iCol: int32): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_column_bytes16".}
+proc sqlite3_column_double*(para1: Psqlite3_stmt, iCol: int32): float64{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_column_double".}
+proc sqlite3_column_int*(para1: Psqlite3_stmt, iCol: int32): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_column_int".}
+proc sqlite3_column_int64*(para1: Psqlite3_stmt, iCol: int32): sqlite_int64{.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_column_int64".}
+proc sqlite3_column_text*(para1: Psqlite3_stmt, iCol: int32): cstring{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_column_text".}
+proc sqlite3_column_text16*(para1: Psqlite3_stmt, iCol: int32): pointer{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_column_text16".}
+proc sqlite3_column_type*(para1: Psqlite3_stmt, iCol: int32): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_column_type".}
+proc sqlite3_finalize*(pStmt: Psqlite3_stmt): int32{.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_finalize".}
+proc sqlite3_reset*(pStmt: Psqlite3_stmt): int32{.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_reset".}
+proc sqlite3_create_function*(para1: Psqlite3, zFunctionName: cstring, 
+                              nArg: int32, eTextRep: int32, para5: pointer, 
+                              xFunc: Tcreate_function_func_func, 
+                              xStep: Tcreate_function_step_func, 
+                              xFinal: Tcreate_function_final_func): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_create_function".}
+proc sqlite3_create_function16*(para1: Psqlite3, zFunctionName: pointer, 
+                                nArg: int32, eTextRep: int32, para5: pointer, 
+                                xFunc: Tcreate_function_func_func, 
+                                xStep: Tcreate_function_step_func, 
+                                xFinal: Tcreate_function_final_func): int32{.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_create_function16".}
+proc sqlite3_aggregate_count*(para1: Psqlite3_context): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_aggregate_count".}
+proc sqlite3_value_blob*(para1: Psqlite3_value): pointer{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_value_blob".}
+proc sqlite3_value_bytes*(para1: Psqlite3_value): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_value_bytes".}
+proc sqlite3_value_bytes16*(para1: Psqlite3_value): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_value_bytes16".}
+proc sqlite3_value_double*(para1: Psqlite3_value): float64{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_value_double".}
+proc sqlite3_value_int*(para1: Psqlite3_value): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_value_int".}
+proc sqlite3_value_int64*(para1: Psqlite3_value): sqlite_int64{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_value_int64".}
+proc sqlite3_value_text*(para1: Psqlite3_value): cstring{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_value_text".}
+proc sqlite3_value_text16*(para1: Psqlite3_value): pointer{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_value_text16".}
+proc sqlite3_value_text16le*(para1: Psqlite3_value): pointer{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_value_text16le".}
+proc sqlite3_value_text16be*(para1: Psqlite3_value): pointer{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_value_text16be".}
+proc sqlite3_value_type*(para1: Psqlite3_value): int32{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_value_type".}
+proc sqlite3_aggregate_context*(para1: Psqlite3_context, nBytes: int32): pointer{.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_aggregate_context".}
+proc sqlite3_user_data*(para1: Psqlite3_context): pointer{.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_user_data".}
+proc sqlite3_get_auxdata*(para1: Psqlite3_context, para2: int32): pointer{.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_get_auxdata".}
+proc sqlite3_set_auxdata*(para1: Psqlite3_context, para2: int32, para3: pointer, 
+                          para4: proc (para1: pointer) {.cdecl.}){.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_set_auxdata".}
+proc sqlite3_result_blob*(para1: Psqlite3_context, para2: pointer, para3: int32, 
+                          para4: Tsqlite3_result_func){.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_result_blob".}
+proc sqlite3_result_double*(para1: Psqlite3_context, para2: float64){.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_result_double".}
+proc sqlite3_result_error*(para1: Psqlite3_context, para2: cstring, para3: int32){.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_result_error".}
+proc sqlite3_result_error16*(para1: Psqlite3_context, para2: pointer, 
+                             para3: int32){.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_result_error16".}
+proc sqlite3_result_int*(para1: Psqlite3_context, para2: int32){.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_result_int".}
+proc sqlite3_result_int64*(para1: Psqlite3_context, para2: sqlite_int64){.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_result_int64".}
+proc sqlite3_result_null*(para1: Psqlite3_context){.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_result_null".}
+proc sqlite3_result_text*(para1: Psqlite3_context, para2: cstring, para3: int32, 
+                          para4: Tsqlite3_result_func){.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_result_text".}
+proc sqlite3_result_text16*(para1: Psqlite3_context, para2: pointer, 
+                            para3: int32, para4: Tsqlite3_result_func){.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_result_text16".}
+proc sqlite3_result_text16le*(para1: Psqlite3_context, para2: pointer, 
+                              para3: int32, para4: Tsqlite3_result_func){.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_result_text16le".}
+proc sqlite3_result_text16be*(para1: Psqlite3_context, para2: pointer, 
+                              para3: int32, para4: Tsqlite3_result_func){.cdecl, 
+    dynlib: Sqlite3Lib, importc: "sqlite3_result_text16be".}
+proc sqlite3_result_value*(para1: Psqlite3_context, para2: Psqlite3_value){.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_result_value".}
+proc sqlite3_create_collation*(para1: Psqlite3, zName: cstring, eTextRep: int32, 
+                               para4: pointer, 
+                               xCompare: Tsqlite3_create_collation_func): int32{.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_create_collation".}
+proc sqlite3_create_collation16*(para1: Psqlite3, zName: cstring, 
+                                 eTextRep: int32, para4: pointer, 
+                                 xCompare: Tsqlite3_create_collation_func): int32{.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_create_collation16".}
+proc sqlite3_collation_needed*(para1: Psqlite3, para2: pointer, 
+                               para3: Tsqlite3_collation_needed_func): int32{.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_collation_needed".}
+proc sqlite3_collation_needed16*(para1: Psqlite3, para2: pointer, 
+                                 para3: Tsqlite3_collation_needed_func): int32{.
+    cdecl, dynlib: Sqlite3Lib, importc: "sqlite3_collation_needed16".}
+proc sqlite3_libversion*(): cstring{.cdecl, dynlib: Sqlite3Lib, 
+                                     importc: "sqlite3_libversion".}
+  #Alias for allowing better code portability (win32 is not working with external variables) 
+proc sqlite3_version*(): cstring{.cdecl, dynlib: Sqlite3Lib, 
+                                  importc: "sqlite3_libversion".}
+  # Not published functions
+proc sqlite3_libversion_number*(): int32{.cdecl, dynlib: Sqlite3Lib, 
+    importc: "sqlite3_libversion_number".}
+  #function sqlite3_key(db:Psqlite3; pKey:pointer; nKey:longint):longint;cdecl; external Sqlite3Lib name 'sqlite3_key';
+  #function sqlite3_rekey(db:Psqlite3; pKey:pointer; nKey:longint):longint;cdecl; external Sqlite3Lib name 'sqlite3_rekey';
+  #function sqlite3_sleep(_para1:longint):longint;cdecl; external Sqlite3Lib name 'sqlite3_sleep';
+  #function sqlite3_expired(_para1:Psqlite3_stmt):longint;cdecl; external Sqlite3Lib name 'sqlite3_expired';
+  #function sqlite3_global_recover:longint;cdecl; external Sqlite3Lib name 'sqlite3_global_recover';
+# implementation
diff --git a/lib/base/terminal.nim b/lib/base/terminal.nim
new file mode 100644
index 000000000..42bd80cb4
--- /dev/null
+++ b/lib/base/terminal.nim
@@ -0,0 +1,310 @@
+#

+#

+#            Nimrod's Runtime Library

+#        (c) Copyright 2009 Andreas Rumpf

+#

+#    See the file "copying.txt", included in this

+#    distribution, for details about the copyright.

+#

+

+## This module contains a few procedures to control the *terminal* 

+## (also called *console*). On UNIX, the implementation simply uses ANSI escape 

+## sequences and does not depend on any other module, on Windows it uses the

+## Windows API.

+## Changing the style is permanent even after program termination! Use the

+## code ``system.addQuitProc(resetAttributes)`` to restore the defaults.

+

+when defined(windows):

+  import windows, os

+  

+  var 

+    conHandle: THandle

+  # = createFile("CONOUT$", GENERIC_WRITE, 0, nil, OPEN_ALWAYS, 0, 0)

+    

+  block:

+    var hTemp = GetStdHandle(STD_OUTPUT_HANDLE())

+    if DuplicateHandle(GetCurrentProcess(), hTemp, GetCurrentProcess(),

+                       addr(conHandle), 0, 1, DUPLICATE_SAME_ACCESS) == 0:

+      OSError()

+    

+  proc getCursorPos(): tuple [x,y: int] = 

+    var c: TCONSOLE_SCREEN_BUFFER_INFO

+    if GetConsoleScreenBufferInfo(conHandle, addr(c)) == 0: OSError()

+    return (int(c.dwCursorPosition.x), int(c.dwCursorPosition.y))

+    

+  proc getAttributes(): int16 = 

+    var c: TCONSOLE_SCREEN_BUFFER_INFO

+    # workaround Windows bugs: try several times

+    if GetConsoleScreenBufferInfo(conHandle, addr(c)) != 0: 

+      return c.wAttributes

+    else:

+      OSError()

+    return 0x70'i16 # ERROR: return white background, black text

+    

+  var

+    oldAttr = getAttributes()

+

+proc setCursorPos*(x, y: int) =

+  ## sets the terminal's cursor to the (x,y) position. (0,0) is the 

+  ## upper left of the screen. 

+  when defined(windows):

+    var c: TCoord

+    c.x = int16(x)

+    c.y = int16(y)

+    if SetConsoleCursorPosition(conHandle, c) == 0: OSError()

+  else:

+    stdout.write("\e[" & $y & ';' & $x & 'f')

+
+proc setCursorXPos*(x: int) =

+  ## sets the terminal's cursor to the x position. The y position is
+  ## not changed.

+  when defined(windows):

+    var scrbuf: TCONSOLE_SCREEN_BUFFER_INFO

+    var hStdout = conHandle

+    if GetConsoleScreenBufferInfo(hStdout, addr(scrbuf)) == 0: OSError()

+    var origin = scrbuf.dwCursorPosition

+    origin.x = int16(x)

+    if SetConsoleCursorPosition(conHandle, origin) == 0: OSError()
+  else:

+    stdout.write("\e[" & $x & 'G')

+
+when defined(windows):
+  proc setCursorYPos*(y: int) =

+    ## sets the terminal's cursor to the y position. The x position is
+    ## not changed. **Warning**: This is not supported on UNIX!

+    when defined(windows):

+      var scrbuf: TCONSOLE_SCREEN_BUFFER_INFO

+      var hStdout = conHandle

+      if GetConsoleScreenBufferInfo(hStdout, addr(scrbuf)) == 0: OSError()

+      var origin = scrbuf.dwCursorPosition

+      origin.y = int16(y)

+      if SetConsoleCursorPosition(conHandle, origin) == 0: OSError()
+    else:

+      nil

+

+proc CursorUp*(count=1) = 

+  ## Moves the cursor up by `count` rows.

+  when defined(windows):

+    var p = getCursorPos()

+    dec(p.y, count)

+    setCursorPos(p.x, p.y)

+  else:

+    stdout.write("\e[" & $count & 'A')

+

+proc CursorDown*(count=1) = 

+  ## Moves the cursor down by `count` rows.

+  when defined(windows):

+    var p = getCursorPos()

+    inc(p.y, count)

+    setCursorPos(p.x, p.y)

+  else:

+    stdout.write("\e[" & $count & 'B')

+

+proc CursorForward*(count=1) = 

+  ## Moves the cursor forward by `count` columns.

+  when defined(windows):

+    var p = getCursorPos()

+    inc(p.x, count)

+    setCursorPos(p.x, p.y)

+  else:

+    stdout.write("\e[" & $count & 'C')

+

+proc CursorBackward*(count=1) = 

+  ## Moves the cursor backward by `count` columns.

+  when defined(windows):

+    var p = getCursorPos()

+    dec(p.x, count)

+    setCursorPos(p.x, p.y)

+  else:

+    stdout.write("\e[" & $count & 'D')

+  

+when true:

+  nil

+else:

+  proc EraseLineEnd* =

+    ## Erases from the current cursor position to the end of the current line.

+    when defined(windows):

+      nil

+    else:

+      stdout.write("\e[K")

+  

+  proc EraseLineStart* =

+    ## Erases from the current cursor position to the start of the current line.

+    when defined(windows):

+      nil

+    else:

+      stdout.write("\e[1K")

+  

+  proc EraseDown* =

+    ## Erases the screen from the current line down to the bottom of the screen.

+    when defined(windows):

+      nil

+    else:

+      stdout.write("\e[J")

+  

+  proc EraseUp* =

+    ## Erases the screen from the current line up to the top of the screen.

+    when defined(windows):

+      nil

+    else:

+      stdout.write("\e[1J")

+  

+proc EraseLine* =

+  ## Erases the entire current line.

+  when defined(windows):

+    var scrbuf: TCONSOLE_SCREEN_BUFFER_INFO

+    var numwrote: DWORD

+    var hStdout = conHandle

+    if GetConsoleScreenBufferInfo(hStdout, addr(scrbuf)) == 0: OSError()

+    var origin = scrbuf.dwCursorPosition

+    origin.x = 0'i16

+    if SetConsoleCursorPosition(conHandle, origin) == 0: OSError()

+    var ht = scrbuf.dwSize.Y - origin.Y

+    var wt = scrbuf.dwSize.X - origin.X

+    if FillConsoleOutputCharacter(hStdout,' ', ht*wt, 

+                                  origin, addr(numwrote)) == 0:

+      OSError()

+    if FillConsoleOutputAttribute(hStdout, scrbuf.wAttributes, ht * wt,

+                                  scrbuf.dwCursorPosition, addr(numwrote)) == 0:

+      OSError()

+  else:

+    stdout.write("\e[2K")
+    setCursorXPos(0)

+

+proc EraseScreen* =

+  ## Erases the screen with the background colour and moves the cursor to home.

+  when defined(windows):

+    var scrbuf: TCONSOLE_SCREEN_BUFFER_INFO

+    var numwrote: DWORD

+    var origin: TCoord # is inititalized to 0, 0 

+    var hStdout = conHandle

+    if GetConsoleScreenBufferInfo(hStdout, addr(scrbuf)) == 0: OSError()

+    if FillConsoleOutputCharacter(hStdout, ' ', scrbuf.dwSize.X*scrbuf.dwSize.Y,

+                                  origin, addr(numwrote)) == 0:

+      OSError()

+    if FillConsoleOutputAttribute(hStdout, scrbuf.wAttributes,

+                                  scrbuf.dwSize.X * scrbuf.dwSize.Y, 

+                                  origin, addr(numwrote)) == 0:

+      OSError()

+    setCursorXPos(0)

+  else:

+    stdout.write("\e[2J")

+

+proc ResetAttributes* {.noconv.} = 

+  ## resets all attributes; it is advisable to register this as a quit proc

+  ## with ``system.addQuitProc(resetAttributes)``. 

+  when defined(windows):

+    discard SetConsoleTextAttribute(conHandle, oldAttr)

+  else:

+    stdout.write("\e[0m")

+

+type

+  TStyle* = enum         ## different styles for text output

+    styleBright = 1,     ## bright text

+    styleDim,            ## dim text

+    styleUnknown,        ## unknown

+    styleUnderscore = 4, ## underscored text

+    styleBlink,          ## blinking/bold text

+    styleReverse,        ## unknown

+    styleHidden          ## hidden text

+

+when not defined(windows):

+  var

+    gFG = 0

+    gBG = 0

+

+proc WriteStyled*(txt: string, style: set[TStyle] = {styleBright}) = 

+  ## writes the text `txt` in a given `style`.

+  when defined(windows):

+    var a = 0'i16

+    if styleBright in style: a = a or int16(FOREGROUND_INTENSITY)

+    if styleBlink in style: a = a or int16(BACKGROUND_INTENSITY)

+    if styleReverse in style: a = a or 0x4000'i16 # COMMON_LVB_REVERSE_VIDEO

+    if styleUnderscore in style: a = a or 0x8000'i16 # COMMON_LVB_UNDERSCORE

+    var old = getAttributes()

+    discard SetConsoleTextAttribute(conHandle, old or a)

+    stdout.write(txt)

+    discard SetConsoleTextAttribute(conHandle, old)

+  else:

+    for s in items(style):

+      stdout.write("\e[" & $ord(s) & 'm')

+    stdout.write(txt)

+    resetAttributes()

+    if gFG != 0: 

+      stdout.write("\e[" & $ord(gFG) & 'm')  

+    if gBG != 0:

+      stdout.write("\e[" & $ord(gBG) & 'm')

+

+type

+  TForegroundColor* = enum ## terminal's foreground colors

+    fgBlack = 30,          ## black

+    fgRed,                 ## red

+    fgGreen,               ## green

+    fgYellow,              ## yellow

+    fgBlue,                ## blue

+    fgMagenta,             ## magenta

+    fgCyan,                ## cyan

+    fgWhite                ## white

+

+  TBackgroundColor* = enum ## terminal's background colors

+    bgBlack = 40,          ## black

+    bgRed,                 ## red

+    bgGreen,               ## green

+    bgYellow,              ## yellow

+    bgBlue,                ## blue

+    bgMagenta,             ## magenta

+    bgCyan,                ## cyan

+    bgWhite                ## white

+  

+proc setForegroundColor*(fg: TForegroundColor, bright=false) = 

+  ## sets the terminal's foreground color

+  when defined(windows):

+    var old = getAttributes() and not 0x0007 

+    if bright: 

+      old = old or FOREGROUND_INTENSITY

+    const lookup: array [TForegroundColor, int] = [

+      0,

+      (FOREGROUND_RED),

+      (FOREGROUND_GREEN),

+      (FOREGROUND_RED or FOREGROUND_GREEN),

+      (FOREGROUND_BLUE),

+      (FOREGROUND_RED or FOREGROUND_BLUE),

+      (FOREGROUND_BLUE or FOREGROUND_GREEN),

+      (FOREGROUND_BLUE or FOREGROUND_GREEN or FOREGROUND_RED)]

+    discard SetConsoleTextAttribute(conHandle, toU16(old or lookup[fg]))

+  else:

+    gFG = ord(fg)

+    if bright: inc(gFG, 60)

+    stdout.write("\e[" & $gFG & 'm')

+

+proc setBackgroundColor*(bg: TBackgroundColor, bright=false) = 

+  ## sets the terminal's background color

+  when defined(windows):

+    var old = getAttributes() and not 0x0070

+    if bright: 

+      old = old or BACKGROUND_INTENSITY

+    const lookup: array [TBackgroundColor, int] = [

+      0,

+      (BACKGROUND_RED),

+      (BACKGROUND_GREEN),

+      (BACKGROUND_RED or BACKGROUND_GREEN),

+      (BACKGROUND_BLUE),

+      (BACKGROUND_RED or BACKGROUND_BLUE),

+      (BACKGROUND_BLUE or BACKGROUND_GREEN),

+      (BACKGROUND_BLUE or BACKGROUND_GREEN or BACKGROUND_RED)]

+    discard SetConsoleTextAttribute(conHandle, toU16(old or lookup[bg]))

+  else:

+    gBG = ord(bg)

+    if bright: inc(gBG, 60)

+    stdout.write("\e[" & $gBG & 'm')

+

+when isMainModule:

+  system.addQuitProc(resetAttributes)

+  write(stdout, "never mind")

+  eraseLine()

+  #setCursorPos(2, 2)

+  writeStyled("styled text ", {styleBright, styleBlink, styleUnderscore})

+  setBackGroundColor(bgCyan, true)

+  setForeGroundColor(fgBlue)

+  writeln(stdout, "ordinary text")

+

diff --git a/lib/base/web.nim b/lib/base/web.nim
new file mode 100644
index 000000000..83d1406af
--- /dev/null
+++ b/lib/base/web.nim
@@ -0,0 +1,57 @@
+#

+#

+#            Nimrod's Runtime Library

+#        (c) Copyright 2009 Andreas Rumpf

+#

+#    See the file "copying.txt", included in this

+#    distribution, for details about the copyright.

+#

+

+## This module contains simple high-level procedures for dealing with the
+## web. Use cases: 
+##
+## * requesting URLs
+## * sending and retrieving emails
+## * sending and retrieving files from an FTP server
+##
+## Currently only requesting URLs is implemented. The implementation depends
+## on the libcurl library!
+
+import libcurl, streams
+
+proc curlwrapperWrite(p: pointer, size, nmemb: int, 
+                      data: pointer): int {.cdecl.} = 
+  var stream = cast[PStream](data)
+  stream.writeData(stream, p, size*nmemb)
+  return size*nmemb
+
+proc URLretrieveStream*(url: string): PStream = 
+  ## retrieves the given `url` and returns a stream which one can read from to
+  ## obtain the contents. Returns nil if an error occurs.
+  result = newStringStream()
+  var hCurl = curl_easy_init() 
+  if hCurl == nil: return nil
+  if curl_easy_setopt(hCurl, CURLOPT_URL, url) != CURLE_OK: return nil
+  if curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, 
+                      curlwrapperWrite) != CURLE_OK: return nil
+  if curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, result) != CURLE_OK: return nil
+  if curl_easy_perform(hCurl) != CURLE_OK: return nil
+  curl_easy_cleanup(hCurl)
+  
+proc URLretrieveString*(url: string): string = 
+  ## retrieves the given `url` and returns the contents. Returns nil if an
+  ## error occurs.
+  var stream = newStringStream()
+  var hCurl = curl_easy_init()
+  if hCurl == nil: return nil
+  if curl_easy_setopt(hCurl, CURLOPT_URL, url) != CURLE_OK: return nil
+  if curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, 
+                      curlwrapperWrite) != CURLE_OK: return nil
+  if curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, stream) != CURLE_OK: return nil
+  if curl_easy_perform(hCurl) != CURLE_OK: return nil
+  curl_easy_cleanup(hCurl)
+  result = stream.data
+
+when isMainModule:
+  echo URLretrieveString("http://nimrod.ethexor.com/")
+