Dim As String datasource: datasource
= "SpriggsyWinServer"
'If DB_Open(datasource) Then
DB_Open datasource
If DB_QUERY
("SELECT * FROM root.table1") = SQL_SUCCESS
Then DB_DetailResult
DB_Close
'Else System
'End If
Const SQL_HANDLE_STMT
= 3 Const SQL_DRIVER_COMPLETE
= 1 Const SQL_NULL_HANDLE
= 0 Const SQL_ATTR_ODBC_VERSION
= 200
SQLAllocHandle SQL_HANDLE_ENV
, SQL_NULL_HANDLE
, Offset(hEnv
) SQLSetEnvAttr hEnv, SQL_ATTR_ODBC_VERSION, SQL_OV_ODBC3, 0
SQLAllocHandle SQL_HANDLE_DBC
, hEnv
, Offset(hDbc
) ret
= SQLDriverConnect
(hDbc
, GetDesktopWindow
, "", SQL_NTS
, Offset(outstr
), Len(outstr
), Offset(outstrlen
), SQL_DRIVER_COMPLETE
) ret
= SQLDriverConnect
(hDbc
, 0, "DSN=" + dsn
+ ";", SQL_NTS
, Offset(outstr
), Len(outstr
), Offset(outstrlen
), SQL_DRIVER_COMPLETE
) ConnectionString
= Mid$(outstr
, 1, outstrlen
) SQLAllocHandle SQL_HANDLE_STMT
, hDbc
, Offset(hStmt
) DB_Open = -1
DB_Error "DB_Open", hDbc, SQL_HANDLE_DBC
DB_Open = 0
Const SQL_HANDLE_STMT
= 3 Const SQL_DRIVER_COMPLETE
= 1 Const SQL_NULL_HANDLE
= 0 Const SQL_ATTR_ODBC_VERSION
= 200
SQLAllocHandle SQL_HANDLE_ENV
, SQL_NULL_HANDLE
, Offset(hEnv
) SQLSetEnvAttr hEnv, SQL_ATTR_ODBC_VERSION, SQL_OV_ODBC3, 0
SQLAllocHandle SQL_HANDLE_DBC
, hEnv
, Offset(hDbc
) ret
= SQLDriverConnect
(hDbc
, GetDesktopWindow
, "", SQL_NTS
, Offset(outstr
), Len(outstr
), Offset(outstrlen
), SQL_DRIVER_COMPLETE
) ret
= SQLDriverConnect
(hDbc
, 0, "DSN=" + dsn
+ ";", SQL_NTS
, Offset(outstr
), Len(outstr
), Offset(outstrlen
), SQL_DRIVER_COMPLETE
) ConnectionString
= Mid$(outstr
, 1, outstrlen
) SQLAllocHandle SQL_HANDLE_STMT
, hDbc
, Offset(hStmt
) DB_Error "DB_Open", hDbc, SQL_HANDLE_DBC
Const SQL_C_CHAR
= SQL_CHAR
Const SQL_NULLABLE_UNKNOWN
= 2
SQLPrepare hStmt, sql_command, SQL_NTS
execCode = SQLExecute(hStmt)
If SQL_SUCCEEDED
(execCode
) Then SQLNumResultCols hStmt
, Offset(columns
) ret = SQLFetch(hStmt)
row = row + 1
Dim As Integer colNameLength
, dataType
, decimalDigits
, nullable
ret
= SQLGetData
(hStmt
, i
, SQL_C_CHAR
, Offset(buf
), Len(buf
), Offset(indicator
)) buf
= Mid$(buf
, 1, indicator
) If indicator
= SQL_NULL_DATA
Then buf
= "NULL" columnName
= Mid$(columnName
, 1, colNameLength
) DB_Result
(i
, row
).
type = dataType
DB_Result(i, row).size = columnSize
DB_Result(i, row).decimalDigits = decimalDigits
DB_Result(i, row).columnName = columnName
DB_Result(i, row).value = buf
DB_Result(i, row).isNullable = 0
DB_Result(i, row).isNullable = -1
ret = SQLFetch(hStmt)
DB_Error "DB_QUERY", hStmt, 3
Const SQL_C_CHAR
= SQL_CHAR
Const SQL_NULLABLE_UNKNOWN
= 2
SQLPrepare hStmt, sql_command, SQL_NTS
execCode = SQLExecute(hStmt)
If SQL_SUCCEEDED
(execCode
) Then SQLNumResultCols hStmt
, Offset(columns
) ret = SQLFetch(hStmt)
row = row + 1
Dim As Integer colNameLength
, dataType
, decimalDigits
, nullable
ret
= SQLGetData
(hStmt
, i
, SQL_C_CHAR
, Offset(buf
), Len(buf
), Offset(indicator
)) buf
= Mid$(buf
, 1, indicator
) If indicator
= SQL_NULL_DATA
Then buf
= "NULL" columnName
= Mid$(columnName
, 1, colNameLength
) DB_Result
(i
, row
).
type = dataType
DB_Result(i, row).size = columnSize
DB_Result(i, row).decimalDigits = decimalDigits
DB_Result(i, row).columnName = columnName
DB_Result(i, row).value = buf
DB_Result(i, row).isNullable = 0
DB_Result(i, row).isNullable = -1
ret = SQLFetch(hStmt)
DB_Error "DB_QUERY", hStmt, 3
DB_QUERY = execCode
DB_Esc = "`" + columnName + "`"
DB_Q = "'" + value + "'"
If SQL_SUCCEEDED
(ret
) Then DB_AffectedRows
= rowCount
Print "Connection: "; ConnectionString
Print " "; column; GetDataType
(DB_Result
(column
, row
).
type);
If DB_Result
(column
, row
).
type = SQL_DECIMAL
Or DB_Result
(column
, row
).
type = SQL_NUMERIC
Then
If DB_Result
(column
, row
).isNullable
= 0 Then Print DB_Result
(column
, row
).columnName;
" "; DB_Result
(column
, row
).value;
" ";
"Not nullable" Else Print DB_Result
(column
, row
).columnName;
" "; DB_Result
(column
, row
).value
SQLDisconnect (hDbc)
SQLFreeHandle SQL_HANDLE_DBC, hDbc
SQLFreeHandle SQL_HANDLE_ENV, hEnv
Const SQL_C_CHAR
= SQL_CHAR
Const SQL_LONGVARCHAR
= -1 Const SQL_WLONGVARCHAR
= -10 Const SQL_LONGVARBINARY
= -4 Const SQL_TYPE_TIMESTAMP
= 93 Const SQL_INTERVAL_MONTH
= -81 Const SQL_INTERVAL_YEAR
= -80 Const SQL_INTERVAL_YEAR_TO_MONTH
= -82 Const SQL_INTERVAL_DAY
= -83 Const SQL_INTERVAL_HOUR
= -84 Const SQL_INTERVAL_MINUTE
= -85 Const SQL_INTERVAL_SECOND
= -86 Const SQL_INTERVAL_DAY_TO_HOUR
= -87 Const SQL_INTERVAL_DAY_TO_MINUTE
= -88 Const SQL_INTERVAL_DAY_TO_SECOND
= -89 Const SQL_INTERVAL_HOUR_TO_MINUTE
= -90 Const SQL_INTERVAL_HOUR_TO_SECOND
= -91 Const SQL_INTERVAL_MINUTE_TO_SECOND
= -92
Case SQL_CHAR
, SQL_C_CHAR
GetDataType = "CHAR"
GetDataType = "VARCHAR"
GetDataType = "LONG VARCHAR"
GetDataType = "WCHAR"
GetDataType = "VARWCHAR"
GetDataType = "LONGWVARCHAR"
GetDataType = "DECIMAL"
GetDataType = "NUMERIC"
GetDataType = "SMALLINT"
GetDataType = "INTEGER"
GetDataType = "REAL"
GetDataType = "FLOAT"
GetDataType = "DOUBLE PRECISION"
GetDataType = "BIT"
GetDataType = "TINYINT"
GetDataType = "BIGINT"
GetDataType = "BINARY"
GetDataType = "VARBINARY"
GetDataType = "LONG VARBINARY"
GetDataType = "DATE"
GetDataType = "TIME"
GetDataType = "TIMESTAMP"
GetDataType = "INTERVAL MONTH"
GetDataType = "INTERVAL YEAR"
Case SQL_INTERVAL_YEAR_TO_MONTH
GetDataType = "INTERVAL YEAR TO MONTH"
GetDataType = "INTERVAL DAY"
GetDataType = "INTERVAL HOUR"
GetDataType = "INTERVAL MINUTE"
GetDataType = "INTERVAL SECOND"
Case SQL_INTERVAL_DAY_TO_HOUR
GetDataType = "INTERVAL DAY TO HOUR"
Case SQL_INTERVAL_DAY_TO_MINUTE
GetDataType = "INTERVAL DAY TO MINUTE"
Case SQL_INTERVAL_DAY_TO_SECOND
GetDataType = "INTERVAL DAY TO SECOND"
Case SQL_INTERVAL_HOUR_TO_MINUTE
GetDataType = "INTERVAL HOUR TO MINUTE"
Case SQL_INTERVAL_HOUR_TO_SECOND
GetDataType = "INTERVAL HOUR TO SECOND"
Case SQL_INTERVAL_MINUTE_TO_SECOND
GetDataType = "INTERVAL MINUTE TO SECOND"
GetDataType = "GUID"
Const MB_OK
= 0 'OK button only Const MB_ICONEXCLAMATION
= 48
i = i + 1
ret
= SQLGetDiagRec
(__type
, handle
, i
, Offset(SQLState
), Offset(NativeError
), Offset(MessageText
), Len(MessageText
), Offset(TextLength
)) MessageBox
0, "Error reported in " + __fn
+ ":" + Chr$(10) + Mid$(SQLState
, 1, InStr(SQLState
, Chr$(0)) - 1) + ":" + Trim$(Str$(i
)) + ":" + Trim$(Str$(NativeError
)) + ":" + Mid$(MessageText
, 1, TextLength
) + Chr$(0), "ODBC Error" + Chr$(0), MB_OK
Or MB_ICONEXCLAMATION
SQL_SUCCEEDED
= (((rc
) And (Not 1)) = 0)