db_odbc.nim 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2015 Nim Contributors
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. ## A higher level `ODBC` database wrapper.
  10. ##
  11. ## This is the same interface that is implemented for other databases.
  12. ##
  13. ## This has NOT yet been (extensively) tested against ODBC drivers for
  14. ## Teradata, Oracle, Sybase, MSSqlvSvr, et. al. databases.
  15. ##
  16. ## Currently all queries are ANSI calls, not Unicode.
  17. ##
  18. ## See also: `db_postgres <db_postgres.html>`_, `db_sqlite <db_sqlite.html>`_,
  19. ## `db_mysql <db_mysql.html>`_.
  20. ##
  21. ## Parameter substitution
  22. ## ======================
  23. ##
  24. ## All ``db_*`` modules support the same form of parameter substitution.
  25. ## That is, using the ``?`` (question mark) to signify the place where a
  26. ## value should be placed. For example:
  27. ##
  28. ## .. code-block:: Nim
  29. ## sql"INSERT INTO myTable (colA, colB, colC) VALUES (?, ?, ?)"
  30. ##
  31. ##
  32. ## Examples
  33. ## ========
  34. ##
  35. ## Opening a connection to a database
  36. ## ----------------------------------
  37. ##
  38. ## .. code-block:: Nim
  39. ## import db_odbc
  40. ## var db = open("localhost", "user", "password", "dbname")
  41. ## db.close()
  42. ##
  43. ## Creating a table
  44. ## ----------------
  45. ##
  46. ## .. code-block:: Nim
  47. ## db.exec(sql"DROP TABLE IF EXISTS myTable")
  48. ## db.exec(sql("""CREATE TABLE myTable (
  49. ## id integer,
  50. ## name varchar(50) not null)"""))
  51. ##
  52. ## Inserting data
  53. ## --------------
  54. ##
  55. ## .. code-block:: Nim
  56. ## db.exec(sql"INSERT INTO myTable (id, name) VALUES (0, ?)",
  57. ## "Andreas")
  58. ##
  59. ## Large example
  60. ## -------------
  61. ##
  62. ## .. code-block:: Nim
  63. ##
  64. ## import db_odbc, math
  65. ##
  66. ## var theDb = open("localhost", "nim", "nim", "test")
  67. ##
  68. ## theDb.exec(sql"Drop table if exists myTestTbl")
  69. ## theDb.exec(sql("create table myTestTbl (" &
  70. ## " Id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, " &
  71. ## " Name VARCHAR(50) NOT NULL, " &
  72. ## " i INT(11), " &
  73. ## " f DECIMAL(18,10))"))
  74. ##
  75. ## theDb.exec(sql"START TRANSACTION")
  76. ## for i in 1..1000:
  77. ## theDb.exec(sql"INSERT INTO myTestTbl (name,i,f) VALUES (?,?,?)",
  78. ## "Item#" & $i, i, sqrt(i.float))
  79. ## theDb.exec(sql"COMMIT")
  80. ##
  81. ## for x in theDb.fastRows(sql"select * from myTestTbl"):
  82. ## echo x
  83. ##
  84. ## let id = theDb.tryInsertId(sql"INSERT INTO myTestTbl (name,i,f) VALUES (?,?,?)",
  85. ## "Item#1001", 1001, sqrt(1001.0))
  86. ## echo "Inserted item: ", theDb.getValue(sql"SELECT name FROM myTestTbl WHERE id=?", id)
  87. ##
  88. ## theDb.close()
  89. import strutils, odbcsql
  90. import db_common
  91. export db_common
  92. type
  93. OdbcConnTyp = tuple[hDb: SqlHDBC, env: SqlHEnv, stmt: SqlHStmt]
  94. DbConn* = OdbcConnTyp ## encapsulates a database connection
  95. Row* = seq[string] ## a row of a dataset. NULL database values will be
  96. ## converted to nil.
  97. InstantRow* = tuple[row: seq[string], len: int] ## a handle that can be
  98. ## used to get a row's
  99. ## column text on demand
  100. var
  101. buf: array[0..4096, char]
  102. proc properFreeResult(hType: int, sqlres: var SqlHandle) {.
  103. tags: [WriteDbEffect], raises: [].} =
  104. try:
  105. discard SQLFreeHandle(hType.TSqlSmallInt, sqlres)
  106. sqlres = nil
  107. except: discard
  108. proc getErrInfo(db: var DbConn): tuple[res: int, ss, ne, msg: string] {.
  109. tags: [ReadDbEffect], raises: [].} =
  110. ## Returns ODBC error information
  111. var
  112. sqlState: array[0..512, char]
  113. nativeErr: array[0..512, char]
  114. errMsg: array[0..512, char]
  115. retSz: TSqlSmallInt = 0
  116. res: TSqlSmallInt = 0
  117. try:
  118. sqlState[0] = '\0'
  119. nativeErr[0] = '\0'
  120. errMsg[0] = '\0'
  121. res = SQLErr(db.env, db.hDb, db.stmt,
  122. cast[PSQLCHAR](sqlState.addr),
  123. cast[PSQLCHAR](nativeErr.addr),
  124. cast[PSQLCHAR](errMsg.addr),
  125. 511.TSqlSmallInt, retSz.addr)
  126. except:
  127. discard
  128. return (res.int, $(addr sqlState), $(addr nativeErr), $(addr errMsg))
  129. proc dbError*(db: var DbConn) {.
  130. tags: [ReadDbEffect, WriteDbEffect], raises: [DbError] .} =
  131. ## Raises an `[DbError]` exception with ODBC error information
  132. var
  133. e: ref DbError
  134. ss, ne, msg: string = ""
  135. isAnError = false
  136. res: int = 0
  137. prevSs = ""
  138. while true:
  139. prevSs = ss
  140. (res, ss, ne, msg) = db.getErrInfo()
  141. if prevSs == ss:
  142. break
  143. # sqlState of 00000 is not an error
  144. elif ss == "00000":
  145. break
  146. elif ss == "01000":
  147. echo "\nWarning: ", ss, " ", msg
  148. continue
  149. else:
  150. isAnError = true
  151. echo "\nError: ", ss, " ", msg
  152. if isAnError:
  153. new(e)
  154. e.msg = "ODBC Error"
  155. if db.stmt != nil:
  156. properFreeResult(SQL_HANDLE_STMT, db.stmt)
  157. properFreeResult(SQL_HANDLE_DBC, db.hDb)
  158. properFreeResult(SQL_HANDLE_ENV, db.env)
  159. raise e
  160. proc sqlCheck(db: var DbConn, resVal: TSqlSmallInt) {.raises: [DbError]} =
  161. ## Wrapper that raises [EDb] if ``resVal`` is neither SQL_SUCCESS or SQL_NO_DATA
  162. if resVal notIn [SQL_SUCCESS, SQL_NO_DATA]: dbError(db)
  163. proc sqlGetDBMS(db: var DbConn): string {.
  164. tags: [ReadDbEffect, WriteDbEffect], raises: [] .} =
  165. ## Returns the ODBC SQL_DBMS_NAME string
  166. const
  167. SQL_DBMS_NAME = 17.SqlUSmallInt
  168. var
  169. sz: TSqlSmallInt = 0
  170. buf[0] = '\0'
  171. try:
  172. db.sqlCheck(SQLGetInfo(db.hDb, SQL_DBMS_NAME, cast[SqlPointer](buf.addr),
  173. 4095.TSqlSmallInt, sz.addr))
  174. except: discard
  175. return $(addr buf)
  176. proc dbQuote*(s: string): string {.noSideEffect.} =
  177. ## DB quotes the string.
  178. result = "'"
  179. for c in items(s):
  180. if c == '\'': add(result, "''")
  181. else: add(result, c)
  182. add(result, '\'')
  183. proc dbFormat(formatstr: SqlQuery, args: varargs[string]): string {.
  184. noSideEffect.} =
  185. ## Replace any ``?`` placeholders with `args`,
  186. ## and quotes the arguments
  187. result = ""
  188. var a = 0
  189. for c in items(string(formatstr)):
  190. if c == '?':
  191. add(result, dbQuote(args[a]))
  192. inc(a)
  193. else:
  194. add(result, c)
  195. proc prepareFetch(db: var DbConn, query: SqlQuery,
  196. args: varargs[string, `$`]): TSqlSmallInt {.
  197. tags: [ReadDbEffect, WriteDbEffect], raises: [DbError].} =
  198. # Prepare a statement, execute it and fetch the data to the driver
  199. # ready for retrieval of the data
  200. # Used internally by iterators and retrieval procs
  201. # requires calling
  202. # properFreeResult(SQL_HANDLE_STMT, db.stmt)
  203. # when finished
  204. db.sqlCheck(SQLAllocHandle(SQL_HANDLE_STMT, db.hDb, db.stmt))
  205. var q = dbFormat(query, args)
  206. db.sqlCheck(SQLPrepare(db.stmt, q.PSQLCHAR, q.len.TSqlSmallInt))
  207. db.sqlCheck(SQLExecute(db.stmt))
  208. result = SQLFetch(db.stmt)
  209. db.sqlCheck(result)
  210. proc prepareFetchDirect(db: var DbConn, query: SqlQuery,
  211. args: varargs[string, `$`]) {.
  212. tags: [ReadDbEffect, WriteDbEffect], raises: [DbError].} =
  213. # Prepare a statement, execute it and fetch the data to the driver
  214. # ready for retrieval of the data
  215. # Used internally by iterators and retrieval procs
  216. # requires calling
  217. # properFreeResult(SQL_HANDLE_STMT, db.stmt)
  218. # when finished
  219. db.sqlCheck(SQLAllocHandle(SQL_HANDLE_STMT, db.hDb, db.stmt))
  220. var q = dbFormat(query, args)
  221. db.sqlCheck(SQLExecDirect(db.stmt, q.PSQLCHAR, q.len.TSqlSmallInt))
  222. db.sqlCheck(SQLFetch(db.stmt))
  223. proc tryExec*(db: var DbConn, query: SqlQuery, args: varargs[string, `$`]): bool {.
  224. tags: [ReadDbEffect, WriteDbEffect], raises: [].} =
  225. ## Tries to execute the query and returns true if successful, false otherwise.
  226. var
  227. res:TSqlSmallInt = -1
  228. try:
  229. db.prepareFetchDirect(query, args)
  230. var
  231. rCnt = -1
  232. res = SQLRowCount(db.stmt, rCnt)
  233. properFreeResult(SQL_HANDLE_STMT, db.stmt)
  234. if res != SQL_SUCCESS: dbError(db)
  235. except: discard
  236. return res == SQL_SUCCESS
  237. proc rawExec(db: var DbConn, query: SqlQuery, args: varargs[string, `$`]) {.
  238. tags: [ReadDbEffect, WriteDbEffect], raises: [DbError].} =
  239. db.prepareFetchDirect(query, args)
  240. proc exec*(db: var DbConn, query: SqlQuery, args: varargs[string, `$`]) {.
  241. tags: [ReadDbEffect, WriteDbEffect], raises: [DbError].} =
  242. ## Executes the query and raises EDB if not successful.
  243. db.prepareFetchDirect(query, args)
  244. properFreeResult(SQL_HANDLE_STMT, db.stmt)
  245. proc newRow(L: int): Row {.noSideEFfect.} =
  246. newSeq(result, L)
  247. for i in 0..L-1: result[i] = ""
  248. iterator fastRows*(db: var DbConn, query: SqlQuery,
  249. args: varargs[string, `$`]): Row {.
  250. tags: [ReadDbEffect, WriteDbEffect], raises: [DbError].} =
  251. ## Executes the query and iterates over the result dataset.
  252. ##
  253. ## This is very fast, but potentially dangerous. Use this iterator only
  254. ## if you require **ALL** the rows.
  255. ##
  256. ## Breaking the fastRows() iterator during a loop may cause a driver error
  257. ## for subsequent queries
  258. ##
  259. ## Rows are retrieved from the server at each iteration.
  260. var
  261. rowRes: Row
  262. sz: TSqlInteger = 0
  263. cCnt: TSqlSmallInt = 0
  264. res: TSqlSmallInt = 0
  265. res = db.prepareFetch(query, args)
  266. if res == SQL_NO_DATA:
  267. discard
  268. elif res == SQL_SUCCESS:
  269. res = SQLNumResultCols(db.stmt, cCnt)
  270. rowRes = newRow(cCnt)
  271. rowRes.setLen(max(cCnt,0))
  272. while res == SQL_SUCCESS:
  273. for colId in 1..cCnt:
  274. buf[0] = '\0'
  275. db.sqlCheck(SQLGetData(db.stmt, colId.SqlUSmallInt, SQL_C_CHAR,
  276. cast[cstring](buf.addr), 4095.TSqlSmallInt,
  277. sz.addr))
  278. rowRes[colId-1] = $(addr buf)
  279. yield rowRes
  280. res = SQLFetch(db.stmt)
  281. properFreeResult(SQL_HANDLE_STMT, db.stmt)
  282. db.sqlCheck(res)
  283. iterator instantRows*(db: var DbConn, query: SqlQuery,
  284. args: varargs[string, `$`]): InstantRow
  285. {.tags: [ReadDbEffect, WriteDbEffect].} =
  286. ## Same as fastRows but returns a handle that can be used to get column text
  287. ## on demand using []. Returned handle is valid only within the iterator body.
  288. var
  289. rowRes: Row = @[]
  290. sz: TSqlInteger = 0
  291. cCnt: TSqlSmallInt = 0
  292. res: TSqlSmallInt = 0
  293. res = db.prepareFetch(query, args)
  294. if res == SQL_NO_DATA:
  295. discard
  296. elif res == SQL_SUCCESS:
  297. res = SQLNumResultCols(db.stmt, cCnt)
  298. rowRes = newRow(cCnt)
  299. rowRes.setLen(max(cCnt,0))
  300. while res == SQL_SUCCESS:
  301. for colId in 1..cCnt:
  302. buf[0] = '\0'
  303. db.sqlCheck(SQLGetData(db.stmt, colId.SqlUSmallInt, SQL_C_CHAR,
  304. cast[cstring](buf.addr), 4095.TSqlSmallInt,
  305. sz.addr))
  306. rowRes[colId-1] = $(addr buf)
  307. yield (row: rowRes, len: cCnt.int)
  308. res = SQLFetch(db.stmt)
  309. properFreeResult(SQL_HANDLE_STMT, db.stmt)
  310. db.sqlCheck(res)
  311. proc `[]`*(row: InstantRow, col: int): string {.inline.} =
  312. ## Returns text for given column of the row
  313. $row.row[col]
  314. proc unsafeColumnAt*(row: InstantRow, index: int): cstring {.inline.} =
  315. ## Return cstring of given column of the row
  316. row.row[index]
  317. proc len*(row: InstantRow): int {.inline.} =
  318. ## Returns number of columns in the row
  319. row.len
  320. proc getRow*(db: var DbConn, query: SqlQuery,
  321. args: varargs[string, `$`]): Row {.
  322. tags: [ReadDbEffect, WriteDbEffect], raises: [DbError].} =
  323. ## Retrieves a single row. If the query doesn't return any rows, this proc
  324. ## will return a Row with empty strings for each column.
  325. var
  326. rowRes: Row
  327. sz: TSqlInteger = 0
  328. cCnt: TSqlSmallInt = 0
  329. res: TSqlSmallInt = 0
  330. res = db.prepareFetch(query, args)
  331. if res == SQL_NO_DATA:
  332. result = @[]
  333. elif res == SQL_SUCCESS:
  334. res = SQLNumResultCols(db.stmt, cCnt)
  335. rowRes = newRow(cCnt)
  336. rowRes.setLen(max(cCnt,0))
  337. for colId in 1..cCnt:
  338. buf[0] = '\0'
  339. db.sqlCheck(SQLGetData(db.stmt, colId.SqlUSmallInt, SQL_C_CHAR,
  340. cast[cstring](buf.addr), 4095.TSqlSmallInt,
  341. sz.addr))
  342. rowRes[colId-1] = $(addr buf)
  343. res = SQLFetch(db.stmt)
  344. result = rowRes
  345. properFreeResult(SQL_HANDLE_STMT, db.stmt)
  346. db.sqlCheck(res)
  347. proc getAllRows*(db: var DbConn, query: SqlQuery,
  348. args: varargs[string, `$`]): seq[Row] {.
  349. tags: [ReadDbEffect, WriteDbEffect], raises: [DbError] .} =
  350. ## Executes the query and returns the whole result dataset.
  351. var
  352. rows: seq[Row] = @[]
  353. rowRes: Row
  354. sz: TSqlInteger = 0
  355. cCnt: TSqlSmallInt = 0
  356. res: TSqlSmallInt = 0
  357. res = db.prepareFetch(query, args)
  358. if res == SQL_NO_DATA:
  359. result = @[]
  360. elif res == SQL_SUCCESS:
  361. res = SQLNumResultCols(db.stmt, cCnt)
  362. rowRes = newRow(cCnt)
  363. rowRes.setLen(max(cCnt,0))
  364. while res == SQL_SUCCESS:
  365. for colId in 1..cCnt:
  366. buf[0] = '\0'
  367. db.sqlCheck(SQLGetData(db.stmt, colId.SqlUSmallInt, SQL_C_CHAR,
  368. cast[cstring](buf.addr), 4095.TSqlSmallInt,
  369. sz.addr))
  370. rowRes[colId-1] = $(addr buf)
  371. rows.add(rowRes)
  372. res = SQLFetch(db.stmt)
  373. result = rows
  374. properFreeResult(SQL_HANDLE_STMT, db.stmt)
  375. db.sqlCheck(res)
  376. iterator rows*(db: var DbConn, query: SqlQuery,
  377. args: varargs[string, `$`]): Row {.
  378. tags: [ReadDbEffect, WriteDbEffect], raises: [DbError].} =
  379. ## Same as `fastRows`, but slower and safe.
  380. ##
  381. ## This retrieves ALL rows into memory before
  382. ## iterating through the rows.
  383. ## Large dataset queries will impact on memory usage.
  384. for r in items(getAllRows(db, query, args)): yield r
  385. proc getValue*(db: var DbConn, query: SqlQuery,
  386. args: varargs[string, `$`]): string {.
  387. tags: [ReadDbEffect, WriteDbEffect], raises: [].} =
  388. ## Executes the query and returns the first column of the first row of the
  389. ## result dataset. Returns "" if the dataset contains no rows or the database
  390. ## value is NULL.
  391. result = ""
  392. try:
  393. result = getRow(db, query, args)[0]
  394. except: discard
  395. proc tryInsertId*(db: var DbConn, query: SqlQuery,
  396. args: varargs[string, `$`]): int64 {.
  397. tags: [ReadDbEffect, WriteDbEffect], raises: [].} =
  398. ## Executes the query (typically "INSERT") and returns the
  399. ## generated ID for the row or -1 in case of an error.
  400. if not tryExec(db, query, args):
  401. result = -1'i64
  402. else:
  403. result = -1'i64
  404. try:
  405. case sqlGetDBMS(db).toLower():
  406. of "postgresql":
  407. result = getValue(db, sql"SELECT LASTVAL();", []).parseInt
  408. of "mysql":
  409. result = getValue(db, sql"SELECT LAST_INSERT_ID();", []).parseInt
  410. of "sqlite":
  411. result = getValue(db, sql"SELECT LAST_INSERT_ROWID();", []).parseInt
  412. of "microsoft sql server":
  413. result = getValue(db, sql"SELECT SCOPE_IDENTITY();", []).parseInt
  414. of "oracle":
  415. result = getValue(db, sql"SELECT id.currval FROM DUAL;", []).parseInt
  416. else: result = -1'i64
  417. except: discard
  418. proc insertId*(db: var DbConn, query: SqlQuery,
  419. args: varargs[string, `$`]): int64 {.
  420. tags: [ReadDbEffect, WriteDbEffect], raises: [DbError].} =
  421. ## Executes the query (typically "INSERT") and returns the
  422. ## generated ID for the row.
  423. result = tryInsertID(db, query, args)
  424. if result < 0: dbError(db)
  425. proc execAffectedRows*(db: var DbConn, query: SqlQuery,
  426. args: varargs[string, `$`]): int64 {.
  427. tags: [ReadDbEffect, WriteDbEffect], raises: [DbError].} =
  428. ## Runs the query (typically "UPDATE") and returns the
  429. ## number of affected rows
  430. result = -1
  431. db.sqlCheck(SQLAllocHandle(SQL_HANDLE_STMT, db.hDb, db.stmt.SqlHandle))
  432. var q = dbFormat(query, args)
  433. db.sqlCheck(SQLPrepare(db.stmt, q.PSQLCHAR, q.len.TSqlSmallInt))
  434. rawExec(db, query, args)
  435. var rCnt = -1
  436. db.sqlCheck(SQLRowCount(db.hDb, rCnt))
  437. properFreeResult(SQL_HANDLE_STMT, db.stmt)
  438. result = rCnt
  439. proc close*(db: var DbConn) {.
  440. tags: [WriteDbEffect], raises: [].} =
  441. ## Closes the database connection.
  442. if db.hDb != nil:
  443. try:
  444. var res = SQLDisconnect(db.hDb)
  445. if db.stmt != nil:
  446. res = SQLFreeHandle(SQL_HANDLE_STMT, db.stmt)
  447. res = SQLFreeHandle(SQL_HANDLE_DBC, db.hDb)
  448. res = SQLFreeHandle(SQL_HANDLE_ENV, db.env)
  449. db = (hDb: nil, env: nil, stmt: nil)
  450. except:
  451. discard
  452. proc open*(connection, user, password, database: string): DbConn {.
  453. tags: [ReadDbEffect, WriteDbEffect], raises: [DbError].} =
  454. ## Opens a database connection.
  455. ##
  456. ## Raises `EDb` if the connection could not be established.
  457. ##
  458. ## Currently the database parameter is ignored,
  459. ## but included to match ``open()`` in the other db_xxxxx library modules.
  460. var
  461. val: TSqlInteger = SQL_OV_ODBC3
  462. resLen = 0
  463. result = (hDb: nil, env: nil, stmt: nil)
  464. # allocate environment handle
  465. var res = SQLAllocHandle(SQL_HANDLE_ENV, result.env, result.env)
  466. if res != SQL_SUCCESS: dbError("Error: unable to initialise ODBC environment.")
  467. res = SQLSetEnvAttr(result.env,
  468. SQL_ATTR_ODBC_VERSION.TSqlInteger,
  469. val, resLen.TSqlInteger)
  470. if res != SQL_SUCCESS: dbError("Error: unable to set ODBC driver version.")
  471. # allocate hDb handle
  472. res = SQLAllocHandle(SQL_HANDLE_DBC, result.env, result.hDb)
  473. if res != SQL_SUCCESS: dbError("Error: unable to allocate connection handle.")
  474. # Connect: connection = dsn str,
  475. res = SQLConnect(result.hDb,
  476. connection.PSQLCHAR , connection.len.TSqlSmallInt,
  477. user.PSQLCHAR, user.len.TSqlSmallInt,
  478. password.PSQLCHAR, password.len.TSqlSmallInt)
  479. if res != SQL_SUCCESS:
  480. result.dbError()
  481. proc setEncoding*(connection: DbConn, encoding: string): bool {.
  482. tags: [ReadDbEffect, WriteDbEffect], raises: [DbError].} =
  483. ## Currently not implemented for ODBC.
  484. ##
  485. ## Sets the encoding of a database connection, returns true for
  486. ## success, false for failure.
  487. ##result = set_character_set(connection, encoding) == 0
  488. dbError("setEncoding() is currently not implemented by the db_odbc module")