Fix wrong integer types in odbcsql and db_odbc (#10419)
* Fix wrong parameter type in SQLErr * Fix wrong types of integers passed to SQLGetData
This commit is contained in:
parent
53eda40d40
commit
a0c07ef863
2 changed files with 19 additions and 47 deletions
|
|
@ -128,7 +128,7 @@ proc getErrInfo(db: var DbConn): tuple[res: int, ss, ne, msg: string] {.
|
||||||
cast[PSQLCHAR](sqlState.addr),
|
cast[PSQLCHAR](sqlState.addr),
|
||||||
cast[PSQLCHAR](nativeErr.addr),
|
cast[PSQLCHAR](nativeErr.addr),
|
||||||
cast[PSQLCHAR](errMsg.addr),
|
cast[PSQLCHAR](errMsg.addr),
|
||||||
511.TSqlSmallInt, retSz.addr.PSQLINTEGER)
|
511.TSqlSmallInt, retSz.addr)
|
||||||
except:
|
except:
|
||||||
discard
|
discard
|
||||||
return (res.int, $(addr sqlState), $(addr nativeErr), $(addr errMsg))
|
return (res.int, $(addr sqlState), $(addr nativeErr), $(addr errMsg))
|
||||||
|
|
@ -277,14 +277,9 @@ iterator fastRows*(db: var DbConn, query: SqlQuery,
|
||||||
## Rows are retrieved from the server at each iteration.
|
## Rows are retrieved from the server at each iteration.
|
||||||
var
|
var
|
||||||
rowRes: Row
|
rowRes: Row
|
||||||
sz: TSqlSmallInt = 0
|
sz: TSqlInteger = 0
|
||||||
cCnt: TSqlSmallInt = 0.TSqlSmallInt
|
cCnt: TSqlSmallInt = 0
|
||||||
res: TSqlSmallInt = 0.TSqlSmallInt
|
res: TSqlSmallInt = 0
|
||||||
tempcCnt: TSqlSmallInt # temporary cCnt,Fix the field values to be null when the release schema is compiled.
|
|
||||||
# tempcCnt,A field to store the number of temporary variables, for unknown reasons,
|
|
||||||
# after performing a sqlgetdata function and circulating variables cCnt value will be changed to 0,
|
|
||||||
# so the values of the temporary variable to store the cCnt.
|
|
||||||
# After every cycle and specified to cCnt. To ensure the traversal of all fields.
|
|
||||||
res = db.prepareFetch(query, args)
|
res = db.prepareFetch(query, args)
|
||||||
if res == SQL_NO_DATA:
|
if res == SQL_NO_DATA:
|
||||||
discard
|
discard
|
||||||
|
|
@ -292,15 +287,13 @@ iterator fastRows*(db: var DbConn, query: SqlQuery,
|
||||||
res = SQLNumResultCols(db.stmt, cCnt)
|
res = SQLNumResultCols(db.stmt, cCnt)
|
||||||
rowRes = newRow(cCnt)
|
rowRes = newRow(cCnt)
|
||||||
rowRes.setLen(max(cCnt,0))
|
rowRes.setLen(max(cCnt,0))
|
||||||
tempcCnt = cCnt
|
|
||||||
while res == SQL_SUCCESS:
|
while res == SQL_SUCCESS:
|
||||||
for colId in 1..cCnt:
|
for colId in 1..cCnt:
|
||||||
buf[0] = '\0'
|
buf[0] = '\0'
|
||||||
db.sqlCheck(SQLGetData(db.stmt, colId.SqlUSmallInt, SQL_C_CHAR,
|
db.sqlCheck(SQLGetData(db.stmt, colId.SqlUSmallInt, SQL_C_CHAR,
|
||||||
cast[cstring](buf.addr), 4095.TSqlSmallInt,
|
cast[cstring](buf.addr), 4095.TSqlSmallInt,
|
||||||
sz.addr.PSQLINTEGER))
|
sz.addr))
|
||||||
rowRes[colId-1] = $(addr buf)
|
rowRes[colId-1] = $(addr buf)
|
||||||
cCnt = tempcCnt
|
|
||||||
yield rowRes
|
yield rowRes
|
||||||
res = SQLFetch(db.stmt)
|
res = SQLFetch(db.stmt)
|
||||||
properFreeResult(SQL_HANDLE_STMT, db.stmt)
|
properFreeResult(SQL_HANDLE_STMT, db.stmt)
|
||||||
|
|
@ -313,14 +306,9 @@ iterator instantRows*(db: var DbConn, query: SqlQuery,
|
||||||
## on demand using []. Returned handle is valid only within the interator body.
|
## on demand using []. Returned handle is valid only within the interator body.
|
||||||
var
|
var
|
||||||
rowRes: Row = @[]
|
rowRes: Row = @[]
|
||||||
sz: TSqlSmallInt = 0
|
sz: TSqlInteger = 0
|
||||||
cCnt: TSqlSmallInt = 0.TSqlSmallInt
|
cCnt: TSqlSmallInt = 0
|
||||||
res: TSqlSmallInt = 0.TSqlSmallInt
|
res: TSqlSmallInt = 0
|
||||||
tempcCnt: TSqlSmallInt # temporary cCnt,Fix the field values to be null when the release schema is compiled.
|
|
||||||
# tempcCnt,A field to store the number of temporary variables, for unknown reasons,
|
|
||||||
# after performing a sqlgetdata function and circulating variables cCnt value will be changed to 0,
|
|
||||||
# so the values of the temporary variable to store the cCnt.
|
|
||||||
# After every cycle and specified to cCnt. To ensure the traversal of all fields.
|
|
||||||
res = db.prepareFetch(query, args)
|
res = db.prepareFetch(query, args)
|
||||||
if res == SQL_NO_DATA:
|
if res == SQL_NO_DATA:
|
||||||
discard
|
discard
|
||||||
|
|
@ -328,15 +316,13 @@ iterator instantRows*(db: var DbConn, query: SqlQuery,
|
||||||
res = SQLNumResultCols(db.stmt, cCnt)
|
res = SQLNumResultCols(db.stmt, cCnt)
|
||||||
rowRes = newRow(cCnt)
|
rowRes = newRow(cCnt)
|
||||||
rowRes.setLen(max(cCnt,0))
|
rowRes.setLen(max(cCnt,0))
|
||||||
tempcCnt = cCnt
|
|
||||||
while res == SQL_SUCCESS:
|
while res == SQL_SUCCESS:
|
||||||
for colId in 1..cCnt:
|
for colId in 1..cCnt:
|
||||||
buf[0] = '\0'
|
buf[0] = '\0'
|
||||||
db.sqlCheck(SQLGetData(db.stmt, colId.SqlUSmallInt, SQL_C_CHAR,
|
db.sqlCheck(SQLGetData(db.stmt, colId.SqlUSmallInt, SQL_C_CHAR,
|
||||||
cast[cstring](buf.addr), 4095.TSqlSmallInt,
|
cast[cstring](buf.addr), 4095.TSqlSmallInt,
|
||||||
sz.addr.PSQLINTEGER))
|
sz.addr))
|
||||||
rowRes[colId-1] = $(addr buf)
|
rowRes[colId-1] = $(addr buf)
|
||||||
cCnt = tempcCnt
|
|
||||||
yield (row: rowRes, len: cCnt.int)
|
yield (row: rowRes, len: cCnt.int)
|
||||||
res = SQLFetch(db.stmt)
|
res = SQLFetch(db.stmt)
|
||||||
properFreeResult(SQL_HANDLE_STMT, db.stmt)
|
properFreeResult(SQL_HANDLE_STMT, db.stmt)
|
||||||
|
|
@ -357,14 +343,9 @@ proc getRow*(db: var DbConn, query: SqlQuery,
|
||||||
## will return a Row with empty strings for each column.
|
## will return a Row with empty strings for each column.
|
||||||
var
|
var
|
||||||
rowRes: Row
|
rowRes: Row
|
||||||
sz: TSqlSmallInt = 0.TSqlSmallInt
|
sz: TSqlInteger = 0
|
||||||
cCnt: TSqlSmallInt = 0.TSqlSmallInt
|
cCnt: TSqlSmallInt = 0
|
||||||
res: TSqlSmallInt = 0.TSqlSmallInt
|
res: TSqlSmallInt = 0
|
||||||
tempcCnt: TSqlSmallInt # temporary cCnt,Fix the field values to be null when the release schema is compiled.
|
|
||||||
## tempcCnt,A field to store the number of temporary variables, for unknown reasons,
|
|
||||||
## after performing a sqlgetdata function and circulating variables cCnt value will be changed to 0,
|
|
||||||
## so the values of the temporary variable to store the cCnt.
|
|
||||||
## After every cycle and specified to cCnt. To ensure the traversal of all fields.
|
|
||||||
res = db.prepareFetch(query, args)
|
res = db.prepareFetch(query, args)
|
||||||
if res == SQL_NO_DATA:
|
if res == SQL_NO_DATA:
|
||||||
result = @[]
|
result = @[]
|
||||||
|
|
@ -372,14 +353,12 @@ proc getRow*(db: var DbConn, query: SqlQuery,
|
||||||
res = SQLNumResultCols(db.stmt, cCnt)
|
res = SQLNumResultCols(db.stmt, cCnt)
|
||||||
rowRes = newRow(cCnt)
|
rowRes = newRow(cCnt)
|
||||||
rowRes.setLen(max(cCnt,0))
|
rowRes.setLen(max(cCnt,0))
|
||||||
tempcCnt = cCnt
|
|
||||||
for colId in 1..cCnt:
|
for colId in 1..cCnt:
|
||||||
buf[0] = '\0'
|
buf[0] = '\0'
|
||||||
db.sqlCheck(SQLGetData(db.stmt, colId.SqlUSmallInt, SQL_C_CHAR,
|
db.sqlCheck(SQLGetData(db.stmt, colId.SqlUSmallInt, SQL_C_CHAR,
|
||||||
cast[cstring](buf.addr), 4095.TSqlSmallInt,
|
cast[cstring](buf.addr), 4095.TSqlSmallInt,
|
||||||
sz.addr.PSQLINTEGER))
|
sz.addr))
|
||||||
rowRes[colId-1] = $(addr buf)
|
rowRes[colId-1] = $(addr buf)
|
||||||
cCnt = tempcCnt
|
|
||||||
res = SQLFetch(db.stmt)
|
res = SQLFetch(db.stmt)
|
||||||
result = rowRes
|
result = rowRes
|
||||||
properFreeResult(SQL_HANDLE_STMT, db.stmt)
|
properFreeResult(SQL_HANDLE_STMT, db.stmt)
|
||||||
|
|
@ -392,14 +371,9 @@ proc getAllRows*(db: var DbConn, query: SqlQuery,
|
||||||
var
|
var
|
||||||
rows: seq[Row] = @[]
|
rows: seq[Row] = @[]
|
||||||
rowRes: Row
|
rowRes: Row
|
||||||
sz: TSqlSmallInt = 0
|
sz: TSqlInteger = 0
|
||||||
cCnt: TSqlSmallInt = 0.TSqlSmallInt
|
cCnt: TSqlSmallInt = 0
|
||||||
res: TSqlSmallInt = 0.TSqlSmallInt
|
res: TSqlSmallInt = 0
|
||||||
tempcCnt: TSqlSmallInt # temporary cCnt,Fix the field values to be null when the release schema is compiled.
|
|
||||||
## tempcCnt,A field to store the number of temporary variables, for unknown reasons,
|
|
||||||
## after performing a sqlgetdata function and circulating variables cCnt value will be changed to 0,
|
|
||||||
## so the values of the temporary variable to store the cCnt.
|
|
||||||
## After every cycle and specified to cCnt. To ensure the traversal of all fields.
|
|
||||||
res = db.prepareFetch(query, args)
|
res = db.prepareFetch(query, args)
|
||||||
if res == SQL_NO_DATA:
|
if res == SQL_NO_DATA:
|
||||||
result = @[]
|
result = @[]
|
||||||
|
|
@ -407,15 +381,13 @@ proc getAllRows*(db: var DbConn, query: SqlQuery,
|
||||||
res = SQLNumResultCols(db.stmt, cCnt)
|
res = SQLNumResultCols(db.stmt, cCnt)
|
||||||
rowRes = newRow(cCnt)
|
rowRes = newRow(cCnt)
|
||||||
rowRes.setLen(max(cCnt,0))
|
rowRes.setLen(max(cCnt,0))
|
||||||
tempcCnt = cCnt
|
|
||||||
while res == SQL_SUCCESS:
|
while res == SQL_SUCCESS:
|
||||||
for colId in 1..cCnt:
|
for colId in 1..cCnt:
|
||||||
buf[0] = '\0'
|
buf[0] = '\0'
|
||||||
db.sqlCheck(SQLGetData(db.stmt, colId.SqlUSmallInt, SQL_C_CHAR,
|
db.sqlCheck(SQLGetData(db.stmt, colId.SqlUSmallInt, SQL_C_CHAR,
|
||||||
cast[cstring](buf.addr), 4095.TSqlSmallInt,
|
cast[cstring](buf.addr), 4095.TSqlSmallInt,
|
||||||
sz.addr.PSQLINTEGER))
|
sz.addr))
|
||||||
rowRes[colId-1] = $(addr buf)
|
rowRes[colId-1] = $(addr buf)
|
||||||
cCnt = tempcCnt
|
|
||||||
rows.add(rowRes)
|
rows.add(rowRes)
|
||||||
res = SQLFetch(db.stmt)
|
res = SQLFetch(db.stmt)
|
||||||
result = rows
|
result = rows
|
||||||
|
|
|
||||||
|
|
@ -830,7 +830,7 @@ proc SQLStatistics*(hstmt: SqlHStmt, CatalogName: PSQLCHAR,
|
||||||
proc SQLErr*(henv: SqlHEnv, hdbc: SqlHDBC, hstmt: SqlHStmt,
|
proc SQLErr*(henv: SqlHEnv, hdbc: SqlHDBC, hstmt: SqlHStmt,
|
||||||
szSqlState, pfNativeError, szErrorMsg: PSQLCHAR,
|
szSqlState, pfNativeError, szErrorMsg: PSQLCHAR,
|
||||||
cbErrorMsgMax: TSqlSmallInt,
|
cbErrorMsgMax: TSqlSmallInt,
|
||||||
pcbErrorMsg: PSQLINTEGER): TSqlSmallInt {.
|
pcbErrorMsg: PSQLSMALLINT): TSqlSmallInt {.
|
||||||
dynlib: odbclib, importc: "SQLError".}
|
dynlib: odbclib, importc: "SQLError".}
|
||||||
|
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue