* fix #9771
* map SQLLEN SQLULEN
* fix proc params take TSqlLen

Co-authored-by: bung87 <crc32@qq.com>
This commit is contained in:
Bung 2020-05-16 03:00:06 +08:00 • committed by GitHub
commit ce0552c100
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 17 deletions

View file

@ -242,7 +242,7 @@ proc tryExec*(db: var DbConn, query: SqlQuery, args: varargs[string, `$`]): bool
try: try:
db.prepareFetchDirect(query, args) db.prepareFetchDirect(query, args)
var var
rCnt = -1 rCnt:TSqlLen = -1
res = SQLRowCount(db.stmt, rCnt) res = SQLRowCount(db.stmt, rCnt)
properFreeResult(SQL_HANDLE_STMT, db.stmt) properFreeResult(SQL_HANDLE_STMT, db.stmt)
if res != SQL_SUCCESS: dbError(db) if res != SQL_SUCCESS: dbError(db)
@ -461,10 +461,10 @@ proc execAffectedRows*(db: var DbConn, query: SqlQuery,
var q = dbFormat(query, args) var q = dbFormat(query, args)
db.sqlCheck(SQLPrepare(db.stmt, q.PSQLCHAR, q.len.TSqlSmallInt)) db.sqlCheck(SQLPrepare(db.stmt, q.PSQLCHAR, q.len.TSqlSmallInt))
rawExec(db, query, args) rawExec(db, query, args)
var rCnt = -1 var rCnt:TSqlLen = -1
db.sqlCheck(SQLRowCount(db.hDb, rCnt)) db.sqlCheck(SQLRowCount(db.hDb, rCnt))
properFreeResult(SQL_HANDLE_STMT, db.stmt) properFreeResult(SQL_HANDLE_STMT, db.stmt)
result = rCnt result = rCnt.int64
proc close*(db: var DbConn) {. proc close*(db: var DbConn) {.
tags: [WriteDbEffect], raises: [].} = tags: [WriteDbEffect], raises: [].} =
@ -489,7 +489,7 @@ proc open*(connection, user, password, database: string): DbConn {.
## Currently the database parameter is ignored, ## Currently the database parameter is ignored,
## but included to match ``open()`` in the other db_xxxxx library modules. ## but included to match ``open()`` in the other db_xxxxx library modules.
var var
val: TSqlInteger = SQL_OV_ODBC3 val = SQL_OV_ODBC3
resLen = 0 resLen = 0
result = (hDb: nil, env: nil, stmt: nil) result = (hDb: nil, env: nil, stmt: nil)
# allocate environment handle # allocate environment handle
@ -497,7 +497,7 @@ proc open*(connection, user, password, database: string): DbConn {.
if res != SQL_SUCCESS: dbError("Error: unable to initialise ODBC environment.") if res != SQL_SUCCESS: dbError("Error: unable to initialise ODBC environment.")
res = SQLSetEnvAttr(result.env, res = SQLSetEnvAttr(result.env,
SQL_ATTR_ODBC_VERSION.TSqlInteger, SQL_ATTR_ODBC_VERSION.TSqlInteger,
val, resLen.TSqlInteger) cast[SqlPointer](val.addr), resLen.TSqlInteger)
if res != SQL_SUCCESS: dbError("Error: unable to set ODBC driver version.") if res != SQL_SUCCESS: dbError("Error: unable to set ODBC driver version.")
# allocate hDb handle # allocate hDb handle
res = SQLAllocHandle(SQL_HANDLE_DBC, result.env, result.hDb) res = SQLAllocHandle(SQL_HANDLE_DBC, result.env, result.hDb)

View file

@ -45,8 +45,10 @@ type
SqlHDBC* = SqlHandle SqlHDBC* = SqlHandle
SqlHStmt* = SqlHandle SqlHStmt* = SqlHandle
SqlHDesc* = SqlHandle SqlHDesc* = SqlHandle
TSqlInteger* = int TSqlInteger* = int32
SqlUInteger* = int SqlUInteger* = int32
TSqlLen* = int64
TSqlULen* = uint64
SqlPointer* = pointer SqlPointer* = pointer
TSqlReal* = cfloat TSqlReal* = cfloat
TSqlDouble* = cdouble TSqlDouble* = cdouble
@ -666,7 +668,7 @@ proc SQLAllocHandle*(HandleType: TSqlSmallInt, InputHandle: SqlHandle,
OutputHandlePtr: var SqlHandle): TSqlSmallInt{. OutputHandlePtr: var SqlHandle): TSqlSmallInt{.
dynlib: odbclib, importc.} dynlib: odbclib, importc.}
proc SQLSetEnvAttr*(EnvironmentHandle: SqlHEnv, Attribute: TSqlInteger, proc SQLSetEnvAttr*(EnvironmentHandle: SqlHEnv, Attribute: TSqlInteger,
Value: TSqlInteger, StringLength: TSqlInteger): TSqlSmallInt{. Value: SqlPointer, StringLength: TSqlInteger): TSqlSmallInt{.
dynlib: odbclib, importc.} dynlib: odbclib, importc.}
proc SQLGetEnvAttr*(EnvironmentHandle: SqlHEnv, Attribute: TSqlInteger, proc SQLGetEnvAttr*(EnvironmentHandle: SqlHEnv, Attribute: TSqlInteger,
Value: SqlPointer, BufferLength: TSqlInteger, Value: SqlPointer, BufferLength: TSqlInteger,
@ -716,14 +718,14 @@ proc SQLNumResultCols*(StatementHandle: SqlHStmt, ColumnCount: var TSqlSmallInt)
proc SQLDescribeCol*(StatementHandle: SqlHStmt, ColumnNumber: SqlUSmallInt, proc SQLDescribeCol*(StatementHandle: SqlHStmt, ColumnNumber: SqlUSmallInt,
ColumnName: PSQLCHAR, BufferLength: TSqlSmallInt, ColumnName: PSQLCHAR, BufferLength: TSqlSmallInt,
NameLength: var TSqlSmallInt, DataType: var TSqlSmallInt, NameLength: var TSqlSmallInt, DataType: var TSqlSmallInt,
ColumnSize: var SqlUInteger, ColumnSize: var TSQLULEN,
DecimalDigits: var TSqlSmallInt, Nullable: var TSqlSmallInt): TSqlSmallInt{. DecimalDigits: var TSqlSmallInt, Nullable: var TSqlSmallInt): TSqlSmallInt{.
dynlib: odbclib, importc.} dynlib: odbclib, importc.}
proc SQLFetchScroll*(StatementHandle: SqlHStmt, FetchOrientation: TSqlSmallInt, proc SQLFetchScroll*(StatementHandle: SqlHStmt, FetchOrientation: TSqlSmallInt,
FetchOffset: TSqlInteger): TSqlSmallInt{.dynlib: odbclib, FetchOffset: TSqlInteger): TSqlSmallInt{.dynlib: odbclib,
importc.} importc.}
proc SQLExtendedFetch*(hstmt: SqlHStmt, fFetchType: SqlUSmallInt, proc SQLExtendedFetch*(hstmt: SqlHStmt, fFetchType: SqlUSmallInt,
irow: TSqlInteger, pcrow: PSQLUINTEGER, irow: TSqlInteger, pcrow: var TSQLULEN,
rgfRowStatus: PSQLUSMALLINT): TSqlSmallInt{.dynlib: odbclib, rgfRowStatus: PSQLUSMALLINT): TSqlSmallInt{.dynlib: odbclib,
importc.} importc.}
proc SQLGetData*(StatementHandle: SqlHStmt, ColumnNumber: SqlUSmallInt, proc SQLGetData*(StatementHandle: SqlHStmt, ColumnNumber: SqlUSmallInt,
@ -741,13 +743,13 @@ proc SQLGetInfo*(ConnectionHandle: SqlHDBC, InfoType: SqlUSmallInt,
InfoValue: SqlPointer, BufferLength: TSqlSmallInt, InfoValue: SqlPointer, BufferLength: TSqlSmallInt,
StringLength: PSQLSMALLINT): TSqlSmallInt{.dynlib: odbclib, StringLength: PSQLSMALLINT): TSqlSmallInt{.dynlib: odbclib,
importc.} importc.}
proc SQLBulkOperations*(StatementHandle: SqlHStmt, Operation: TSqlSmallInt): TSqlSmallInt{. proc SQLBulkOperations*(StatementHandle: SqlHStmt, Operation: SqlUSmallInt): TSqlSmallInt{.
dynlib: odbclib, importc.} dynlib: odbclib, importc.}
proc SQLPutData*(StatementHandle: SqlHStmt, Data: SqlPointer, proc SQLPutData*(StatementHandle: SqlHStmt, Data: SqlPointer,
StrLen_or_Ind: TSqlInteger): TSqlSmallInt{.dynlib: odbclib, importc.} StrLen_or_Ind: TSQLLEN): TSqlSmallInt{.dynlib: odbclib, importc.}
proc SQLBindCol*(StatementHandle: SqlHStmt, ColumnNumber: SqlUSmallInt, proc SQLBindCol*(StatementHandle: SqlHStmt, ColumnNumber: SqlUSmallInt,
TargetType: TSqlSmallInt, TargetValue: SqlPointer, TargetType: TSqlSmallInt, TargetValue: SqlPointer,
BufferLength: TSqlInteger, StrLen_or_Ind: PSQLINTEGER): TSqlSmallInt{. BufferLength: TSqlLEN, StrLen_or_Ind: PSQLINTEGER): TSqlSmallInt{.
dynlib: odbclib, importc.} dynlib: odbclib, importc.}
proc SQLSetPos*(hstmt: SqlHStmt, irow: SqlUSmallInt, fOption: SqlUSmallInt, proc SQLSetPos*(hstmt: SqlHStmt, irow: SqlUSmallInt, fOption: SqlUSmallInt,
fLock: SqlUSmallInt): TSqlSmallInt{.dynlib: odbclib, importc.} fLock: SqlUSmallInt): TSqlSmallInt{.dynlib: odbclib, importc.}
@ -770,13 +772,13 @@ proc SQLGetCursorName*(StatementHandle: SqlHStmt, CursorName: PSQLCHAR,
proc SQLSetCursorName*(StatementHandle: SqlHStmt, CursorName: PSQLCHAR, proc SQLSetCursorName*(StatementHandle: SqlHStmt, CursorName: PSQLCHAR,
NameLength: TSqlSmallInt): TSqlSmallInt{.dynlib: odbclib, NameLength: TSqlSmallInt): TSqlSmallInt{.dynlib: odbclib,
importc.} importc.}
proc SQLRowCount*(StatementHandle: SqlHStmt, RowCount: var TSqlInteger): TSqlSmallInt{. proc SQLRowCount*(StatementHandle: SqlHStmt, RowCount: var TSQLLEN): TSqlSmallInt{.
dynlib: odbclib, importc.} dynlib: odbclib, importc.}
proc SQLBindParameter*(hstmt: SqlHStmt, ipar: SqlUSmallInt, proc SQLBindParameter*(hstmt: SqlHStmt, ipar: SqlUSmallInt,
fParamType: TSqlSmallInt, fCType: TSqlSmallInt, fParamType: TSqlSmallInt, fCType: TSqlSmallInt,
fSqlType: TSqlSmallInt, cbColDef: SqlUInteger, fSqlType: TSqlSmallInt, cbColDef: TSQLULEN,
ibScale: TSqlSmallInt, rgbValue: SqlPointer, ibScale: TSqlSmallInt, rgbValue: SqlPointer,
cbValueMax: TSqlInteger, pcbValue: PSQLINTEGER): TSqlSmallInt{. cbValueMax: TSQLLEN, pcbValue: var TSQLLEN): TSqlSmallInt{.
dynlib: odbclib, importc.} dynlib: odbclib, importc.}
proc SQLFreeStmt*(StatementHandle: SqlHStmt, Option: SqlUSmallInt): TSqlSmallInt{. proc SQLFreeStmt*(StatementHandle: SqlHStmt, Option: SqlUSmallInt): TSqlSmallInt{.
dynlib: odbclib, importc.} dynlib: odbclib, importc.}
@ -784,7 +786,7 @@ proc SQLColAttribute*(StatementHandle: SqlHStmt, ColumnNumber: SqlUSmallInt,
FieldIdentifier: SqlUSmallInt, FieldIdentifier: SqlUSmallInt,
CharacterAttribute: PSQLCHAR, BufferLength: TSqlSmallInt, CharacterAttribute: PSQLCHAR, BufferLength: TSqlSmallInt,
StringLength: PSQLSMALLINT, StringLength: PSQLSMALLINT,
NumericAttribute: SqlPointer): TSqlSmallInt{. NumericAttribute: TSQLLEN): TSqlSmallInt{.
dynlib: odbclib, importc.} dynlib: odbclib, importc.}
proc SQLEndTran*(HandleType: TSqlSmallInt, Handle: SqlHandle, proc SQLEndTran*(HandleType: TSqlSmallInt, Handle: SqlHandle,
CompletionType: TSqlSmallInt): TSqlSmallInt{.dynlib: odbclib, CompletionType: TSqlSmallInt): TSqlSmallInt{.dynlib: odbclib,