odbc, odbc-docs: fix indentation, remove trailing whitespace
parent
ca0fa560da
commit
c78afe8c53
|
@ -4,96 +4,119 @@ USING: help.syntax help.markup threads ;
|
||||||
|
|
||||||
IN: odbc
|
IN: odbc
|
||||||
|
|
||||||
HELP: odbc-init
|
HELP: odbc-init
|
||||||
{ $values { "env" "an ODBC environment handle" } }
|
{ $values { "env" "an ODBC environment handle" } }
|
||||||
{ $description
|
{ $description
|
||||||
"Initializes the ODBC driver manager and returns the "
|
"Initializes the ODBC driver manager and returns the "
|
||||||
"environment handle required by " { $link odbc-connect } "."
|
"environment handle required by " { $link odbc-connect } "."
|
||||||
}
|
}
|
||||||
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
||||||
|
|
||||||
HELP: odbc-connect
|
HELP: odbc-connect
|
||||||
{ $values { "env" "an ODBC environment handle" } { "dsn" "a string" } { "dbc" "an ODBC database connection handle" } }
|
{ $values
|
||||||
{ $description
|
{ "env" "an ODBC environment handle" }
|
||||||
"Connects to the database identified by the ODBC data source name (DSN). "
|
{ "dsn" "a string" }
|
||||||
"The environment handle is usually obtained by a call to " { $link odbc-init } ". The result is the ODBC connection handle which can be used in other ODBC calls. When finished with the connection handle " { $link odbc-disconnect } " must be called on it."
|
{ "dbc" "an ODBC database connection handle" }
|
||||||
}
|
}
|
||||||
|
{ $description
|
||||||
|
"Connects to the database identified by the ODBC data source name (DSN). "
|
||||||
|
"The environment handle is usually obtained by a call to " { $link odbc-init } ". The result is the ODBC connection handle which can be used in other ODBC calls. When finished with the connection handle " { $link odbc-disconnect } " must be called on it."
|
||||||
|
}
|
||||||
{ $examples { $code "dbc get \"DSN=mydsn\" odbc-connect" } }
|
{ $examples { $code "dbc get \"DSN=mydsn\" odbc-connect" } }
|
||||||
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
||||||
|
|
||||||
HELP: odbc-disconnect
|
HELP: odbc-disconnect
|
||||||
{ $values { "dbc" "an ODBC database connection handle" } }
|
{ $values { "dbc" "an ODBC database connection handle" } }
|
||||||
{ $description
|
{ $description
|
||||||
"Disconnects from the given database."
|
"Disconnects from the given database."
|
||||||
}
|
}
|
||||||
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
||||||
|
|
||||||
HELP: odbc-prepare
|
HELP: odbc-prepare
|
||||||
{ $values { "dbc" "an ODBC database connection handle" } { "string" "a string containing SQL" } { "statement" "an ODBC statement handle" } }
|
{ $values
|
||||||
{ $description
|
{ "dbc" "an ODBC database connection handle" }
|
||||||
"Prepares (precompiles) the given SQL string, ready for execution with " { $link odbc-execute } ". When finished with the statement " { $link odbc-free-statement } " must be called on it."
|
{ "string" "a string containing SQL" }
|
||||||
}
|
{ "statement" "an ODBC statement handle" }
|
||||||
|
}
|
||||||
|
{ $description
|
||||||
|
"Prepares (precompiles) the given SQL string, ready for execution with " { $link odbc-execute } ". When finished with the statement " { $link odbc-free-statement } " must be called on it."
|
||||||
|
}
|
||||||
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
||||||
|
|
||||||
HELP: odbc-free-statement
|
HELP: odbc-free-statement
|
||||||
{ $values { "statement" "an ODBC statement handle" } }
|
{ $values { "statement" "an ODBC statement handle" } }
|
||||||
{ $description
|
{ $description
|
||||||
"Closes the statement handle and frees up all resources associated with it."
|
"Closes the statement handle and frees up all resources associated with it."
|
||||||
}
|
}
|
||||||
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
||||||
|
|
||||||
HELP: odbc-execute
|
HELP: odbc-execute
|
||||||
{ $values { "statement" "an ODBC statement handle" } }
|
{ $values { "statement" "an ODBC statement handle" } }
|
||||||
{ $description
|
{ $description
|
||||||
"Executes the statement. Once this is done " { $link odbc-next-row } " can be called to retrieve rows."
|
"Executes the statement. Once this is done " { $link odbc-next-row } " can be called to retrieve rows."
|
||||||
}
|
}
|
||||||
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
||||||
|
|
||||||
HELP: odbc-next-row
|
HELP: odbc-next-row
|
||||||
{ $values { "statement" "an ODBC statement handle" } { "bool" "a boolean indicating success or failure" } }
|
{ $values
|
||||||
{ $description
|
{ "statement" "an ODBC statement handle" }
|
||||||
"Retrieves the next available row from the database. If no next row is available then " { $link f } " is returned. Once the row is retrieved " { $link odbc-number-of-columns } ", " { $link odbc-describe-column } ", " { $link odbc-get-field } " and " { $link odbc-get-row-fields } " can be used to query the data retrieved."
|
{ "bool" "a boolean indicating success or failure" }
|
||||||
}
|
}
|
||||||
|
{ $description
|
||||||
|
"Retrieves the next available row from the database. If no next row is available then " { $link f } " is returned. Once the row is retrieved " { $link odbc-number-of-columns } ", " { $link odbc-describe-column } ", " { $link odbc-get-field } " and " { $link odbc-get-row-fields } " can be used to query the data retrieved."
|
||||||
|
}
|
||||||
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
||||||
|
|
||||||
HELP: odbc-number-of-columns
|
HELP: odbc-number-of-columns
|
||||||
{ $values { "statement" "an ODBC statement handle" } { "number" "a number" } }
|
{ $values { "statement" "an ODBC statement handle" } { "number" "a number" } }
|
||||||
{ $description
|
{ $description
|
||||||
"Returns the number of columns of data retrieved."
|
"Returns the number of columns of data retrieved."
|
||||||
}
|
}
|
||||||
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
||||||
|
|
||||||
HELP: odbc-describe-column
|
HELP: odbc-describe-column
|
||||||
{ $values { "statement" "an ODBC statement handle" } { "n" "a column number starting from one" } { "column" "a column object" } }
|
{ $values
|
||||||
{ $description
|
{ "statement" "an ODBC statement handle" }
|
||||||
|
{ "n" "a column number starting from one" }
|
||||||
|
{ "column" "a column object" }
|
||||||
|
}
|
||||||
|
{ $description
|
||||||
"Retrieves column information for the given column number from the statement. The column number must be one or greater. The " { $link <column> } " object returned provides data type, name, etc."
|
"Retrieves column information for the given column number from the statement. The column number must be one or greater. The " { $link <column> } " object returned provides data type, name, etc."
|
||||||
}
|
}
|
||||||
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
||||||
|
|
||||||
HELP: odbc-get-field
|
HELP: odbc-get-field
|
||||||
{ $values { "statement" "an ODBC statement handle" } { "column" "a column number starting from one or a <column> object" } { "field" "a <field> object" } }
|
{ $values
|
||||||
{ $description
|
{ "statement" "an ODBC statement handle" }
|
||||||
|
{ "column" "a column number starting from one or a <column> object" }
|
||||||
|
{ "field" "a <field> object" }
|
||||||
|
}
|
||||||
|
{ $description
|
||||||
"Returns a field object which contains the data for the field in the given column in the current row. The column can be identified by a number or a <column> object. The datatype of the contents of the field depends on the type of the column itself. Note that this word can only be safely called once on each column in a given row with most ODBC drivers. Subsequent calls on the same row for the same column can fail."
|
"Returns a field object which contains the data for the field in the given column in the current row. The column can be identified by a number or a <column> object. The datatype of the contents of the field depends on the type of the column itself. Note that this word can only be safely called once on each column in a given row with most ODBC drivers. Subsequent calls on the same row for the same column can fail."
|
||||||
}
|
}
|
||||||
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
||||||
|
|
||||||
HELP: odbc-get-row-fields
|
HELP: odbc-get-row-fields
|
||||||
{ $values { "statement" "an ODBC statement handle" } { "seq" "a sequence" } }
|
{ $values { "statement" "an ODBC statement handle" } { "seq" "a sequence" } }
|
||||||
{ $description
|
{ $description
|
||||||
"Returns a sequence of all field data for the current row. Note that this is not the <field> objects, but the data for that field. This word can only be called once on a given row. Subsequent calls on the same row may fail on some ODBC drivers."
|
"Returns a sequence of all field data for the current row. Note that this is not the <field> objects, but the data for that field. This word can only be called once on a given row. Subsequent calls on the same row may fail on some ODBC drivers."
|
||||||
}
|
}
|
||||||
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
||||||
|
|
||||||
HELP: odbc-get-all-rows
|
HELP: odbc-get-all-rows
|
||||||
{ $values { "statement" "an ODBC statement handle" } { "seq" "a sequence" } }
|
{ $values { "statement" "an ODBC statement handle" } { "seq" "a sequence" } }
|
||||||
{ $description
|
{ $description
|
||||||
"Returns a sequence of all rows available from the statement. Effectively it is the contents of the entire query so may take some time and memory. Each element of the sequence is itself a sequence containing the data for that row. A " { $link yield } " is performed an various intervals so as to not lock up the Factor instance while it is running."
|
"Returns a sequence of all rows available from the statement. Effectively it is the contents of the entire query so may take some time and memory. Each element of the sequence is itself a sequence containing the data for that row. A " { $link yield } " is performed an various intervals so as to not lock up the Factor instance while it is running."
|
||||||
}
|
}
|
||||||
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
||||||
|
|
||||||
HELP: odbc-query
|
HELP: odbc-query
|
||||||
{ $values { "string" "a string containing SQL" } { "dsn" "a DSN string" } { "result" "a sequence" } }
|
{ $values
|
||||||
{ $description
|
{ "string" "a string containing SQL" }
|
||||||
|
{ "dsn" "a DSN string" }
|
||||||
|
{ "result" "a sequence" }
|
||||||
|
}
|
||||||
|
{ $description
|
||||||
"This word initializes odbc, connects to the database with the given DSN, executes the query string and returns the result as a sequence. It cleans up all resources it uses. It is an inefficient way of running multiple queries but is useful for the occasional query, testing at the REPL, or as an example of how to do it."
|
"This word initializes odbc, connects to the database with the given DSN, executes the query string and returns the result as a sequence. It cleans up all resources it uses. It is an inefficient way of running multiple queries but is useful for the occasional query, testing at the REPL, or as an example of how to do it."
|
||||||
}
|
}
|
||||||
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
{ $see-also odbc-init odbc-connect odbc-disconnect odbc-prepare odbc-free-statement odbc-execute odbc-next-row odbc-number-of-columns odbc-describe-column odbc-get-field odbc-get-row-fields odbc-get-all-rows odbc-query } ;
|
||||||
|
|
|
@ -85,39 +85,39 @@ SYMBOL: SQL-GUID
|
||||||
SYMBOL: SQL-TYPE-UNKNOWN
|
SYMBOL: SQL-TYPE-UNKNOWN
|
||||||
|
|
||||||
: convert-sql-type ( number -- symbol )
|
: convert-sql-type ( number -- symbol )
|
||||||
{
|
{
|
||||||
{ 1 [ SQL-CHAR ] }
|
{ 1 [ SQL-CHAR ] }
|
||||||
{ 12 [ SQL-VARCHAR ] }
|
{ 12 [ SQL-VARCHAR ] }
|
||||||
{ -1 [ SQL-LONGVARCHAR ] }
|
{ -1 [ SQL-LONGVARCHAR ] }
|
||||||
{ -8 [ SQL-WCHAR ] }
|
{ -8 [ SQL-WCHAR ] }
|
||||||
{ -9 [ SQL-WCHARVAR ] }
|
{ -9 [ SQL-WCHARVAR ] }
|
||||||
{ -10 [ SQL-WLONGCHARVAR ] }
|
{ -10 [ SQL-WLONGCHARVAR ] }
|
||||||
{ 3 [ SQL-DECIMAL ] }
|
{ 3 [ SQL-DECIMAL ] }
|
||||||
{ 5 [ SQL-SMALLINT ] }
|
{ 5 [ SQL-SMALLINT ] }
|
||||||
{ 2 [ SQL-NUMERIC ] }
|
{ 2 [ SQL-NUMERIC ] }
|
||||||
{ 4 [ SQL-INTEGER ] }
|
{ 4 [ SQL-INTEGER ] }
|
||||||
{ 7 [ SQL-REAL ] }
|
{ 7 [ SQL-REAL ] }
|
||||||
{ 6 [ SQL-FLOAT ] }
|
{ 6 [ SQL-FLOAT ] }
|
||||||
{ 8 [ SQL-DOUBLE ] }
|
{ 8 [ SQL-DOUBLE ] }
|
||||||
{ -7 [ SQL-BIT ] }
|
{ -7 [ SQL-BIT ] }
|
||||||
{ -6 [ SQL-TINYINT ] }
|
{ -6 [ SQL-TINYINT ] }
|
||||||
{ -5 [ SQL-BIGINT ] }
|
{ -5 [ SQL-BIGINT ] }
|
||||||
{ -2 [ SQL-BINARY ] }
|
{ -2 [ SQL-BINARY ] }
|
||||||
{ -3 [ SQL-VARBINARY ] }
|
{ -3 [ SQL-VARBINARY ] }
|
||||||
{ -4 [ SQL-LONGVARBINARY ] }
|
{ -4 [ SQL-LONGVARBINARY ] }
|
||||||
{ 91 [ SQL-TYPE-DATE ] }
|
{ 91 [ SQL-TYPE-DATE ] }
|
||||||
{ 92 [ SQL-TYPE-TIME ] }
|
{ 92 [ SQL-TYPE-TIME ] }
|
||||||
{ 93 [ SQL-TYPE-TIMESTAMP ] }
|
{ 93 [ SQL-TYPE-TIMESTAMP ] }
|
||||||
[ drop SQL-TYPE-UNKNOWN ]
|
[ drop SQL-TYPE-UNKNOWN ]
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
: succeeded? ( n -- bool )
|
: succeeded? ( n -- bool )
|
||||||
! Did the call succeed (SQL-SUCCESS or SQL-SUCCESS-WITH-INFO)
|
! Did the call succeed (SQL-SUCCESS or SQL-SUCCESS-WITH-INFO)
|
||||||
{
|
{
|
||||||
{ SQL-SUCCESS [ t ] }
|
{ SQL-SUCCESS [ t ] }
|
||||||
{ SQL-SUCCESS-WITH-INFO [ t ] }
|
{ SQL-SUCCESS-WITH-INFO [ t ] }
|
||||||
[ drop f ]
|
[ drop f ]
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
FUNCTION: SQLRETURN SQLAllocHandle ( SQLSMALLINT handleType, SQLHANDLE inputHandle, SQLHANDLE* outputHandlePtr )
|
FUNCTION: SQLRETURN SQLAllocHandle ( SQLSMALLINT handleType, SQLHANDLE inputHandle, SQLHANDLE* outputHandlePtr )
|
||||||
FUNCTION: SQLRETURN SQLSetEnvAttr ( SQLHENV environmentHandle, SQLINTEGER attribute, SQLPOINTER valuePtr, SQLINTEGER stringLength )
|
FUNCTION: SQLRETURN SQLSetEnvAttr ( SQLHENV environmentHandle, SQLINTEGER attribute, SQLPOINTER valuePtr, SQLINTEGER stringLength )
|
||||||
|
@ -132,20 +132,20 @@ FUNCTION: SQLRETURN SQLDescribeCol ( SQLHSTMT statementHandle, SQLSMALLINT colum
|
||||||
FUNCTION: SQLRETURN SQLGetData ( SQLHSTMT statementHandle, SQLUSMALLINT columnNumber, SQLSMALLINT targetType, SQLPOINTER targetValuePtr, SQLINTEGER bufferLength, SQLINTEGER* strlen_or_indPtr )
|
FUNCTION: SQLRETURN SQLGetData ( SQLHSTMT statementHandle, SQLUSMALLINT columnNumber, SQLSMALLINT targetType, SQLPOINTER targetValuePtr, SQLINTEGER bufferLength, SQLINTEGER* strlen_or_indPtr )
|
||||||
|
|
||||||
: alloc-handle ( type parent -- handle )
|
: alloc-handle ( type parent -- handle )
|
||||||
f void* <ref> [ SQLAllocHandle ] keep swap succeeded? [
|
f void* <ref> [ SQLAllocHandle ] keep swap succeeded? [
|
||||||
void* deref
|
void* deref
|
||||||
] [
|
] [
|
||||||
drop f
|
drop f
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: alloc-env-handle ( -- handle )
|
: alloc-env-handle ( -- handle )
|
||||||
SQL-HANDLE-ENV SQL-NULL-HANDLE alloc-handle ;
|
SQL-HANDLE-ENV SQL-NULL-HANDLE alloc-handle ;
|
||||||
|
|
||||||
: alloc-dbc-handle ( env -- handle )
|
: alloc-dbc-handle ( env -- handle )
|
||||||
SQL-HANDLE-DBC swap alloc-handle ;
|
SQL-HANDLE-DBC swap alloc-handle ;
|
||||||
|
|
||||||
: alloc-stmt-handle ( dbc -- handle )
|
: alloc-stmt-handle ( dbc -- handle )
|
||||||
SQL-HANDLE-STMT swap alloc-handle ;
|
SQL-HANDLE-STMT swap alloc-handle ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
@ -155,121 +155,130 @@ FUNCTION: SQLRETURN SQLGetData ( SQLHSTMT statementHandle, SQLUSMALLINT columnNu
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: temp-string ( length -- byte-array length )
|
: temp-string ( length -- byte-array length )
|
||||||
[ alien-space-str ] keep ;
|
[ alien-space-str ] keep ;
|
||||||
|
|
||||||
: odbc-init ( -- env )
|
: odbc-init ( -- env )
|
||||||
alloc-env-handle
|
alloc-env-handle
|
||||||
[
|
[
|
||||||
SQL-ATTR-ODBC-VERSION SQL-OV-ODBC3 0 SQLSetEnvAttr
|
SQL-ATTR-ODBC-VERSION SQL-OV-ODBC3 0 SQLSetEnvAttr
|
||||||
succeeded? [ "odbc-init failed" throw ] unless
|
succeeded? [ "odbc-init failed" throw ] unless
|
||||||
] keep ;
|
] keep ;
|
||||||
|
|
||||||
: odbc-connect ( env dsn -- dbc )
|
: odbc-connect ( env dsn -- dbc )
|
||||||
[ alloc-dbc-handle dup ] dip
|
[ alloc-dbc-handle dup ] dip
|
||||||
f swap dup length 1024 temp-string 0 short <ref> SQL-DRIVER-NOPROMPT
|
f swap dup length 1024 temp-string 0 short <ref> SQL-DRIVER-NOPROMPT SQLDriverConnect
|
||||||
SQLDriverConnect succeeded? [ "odbc-connect failed" throw ] unless ;
|
succeeded? [ "odbc-connect failed" throw ] unless ;
|
||||||
|
|
||||||
: odbc-disconnect ( dbc -- )
|
: odbc-disconnect ( dbc -- )
|
||||||
SQLDisconnect succeeded? [ "odbc-disconnect failed" throw ] unless ;
|
SQLDisconnect succeeded? [ "odbc-disconnect failed" throw ] unless ;
|
||||||
|
|
||||||
: odbc-prepare ( dbc string -- statement )
|
: odbc-prepare ( dbc string -- statement )
|
||||||
[ alloc-stmt-handle dup ] dip dup length SQLPrepare succeeded? [ "odbc-prepare failed" throw ] unless ;
|
[ alloc-stmt-handle dup ] dip dup length SQLPrepare
|
||||||
|
succeeded? [ "odbc-prepare failed" throw ] unless ;
|
||||||
|
|
||||||
: odbc-free-statement ( statement -- )
|
: odbc-free-statement ( statement -- )
|
||||||
SQL-HANDLE-STMT swap SQLFreeHandle succeeded? [ "odbc-free-statement failed" throw ] unless ;
|
SQL-HANDLE-STMT swap SQLFreeHandle
|
||||||
|
succeeded? [ "odbc-free-statement failed" throw ] unless ;
|
||||||
|
|
||||||
: odbc-execute ( statement -- )
|
: odbc-execute ( statement -- )
|
||||||
SQLExecute succeeded? [ "odbc-execute failed" throw ] unless ;
|
SQLExecute succeeded? [ "odbc-execute failed" throw ] unless ;
|
||||||
|
|
||||||
: odbc-next-row ( statement -- bool )
|
: odbc-next-row ( statement -- bool )
|
||||||
SQLFetch succeeded? ;
|
SQLFetch succeeded? ;
|
||||||
|
|
||||||
: odbc-number-of-columns ( statement -- number )
|
: odbc-number-of-columns ( statement -- number )
|
||||||
0 short <ref> [ SQLNumResultCols succeeded? ] keep swap [
|
0 short <ref> [ SQLNumResultCols succeeded? ] keep swap [
|
||||||
short deref
|
short deref
|
||||||
] [
|
] [
|
||||||
drop f
|
drop f
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
TUPLE: column nullable digits size type name number ;
|
TUPLE: column nullable digits size type name number ;
|
||||||
|
|
||||||
C: <column> column
|
C: <column> column
|
||||||
|
|
||||||
:: odbc-describe-column ( statement columnNumber -- column )
|
:: odbc-describe-column ( statement columnNumber -- column )
|
||||||
1024 :> bufferLen
|
1024 :> bufferLen
|
||||||
bufferLen alien-space-str :> columnName
|
bufferLen alien-space-str :> columnName
|
||||||
0 short <ref> :> nameLengthPtr
|
0 short <ref> :> nameLengthPtr
|
||||||
0 short <ref> :> dataTypePtr
|
0 short <ref> :> dataTypePtr
|
||||||
0 uint <ref> :> columnSizePtr
|
0 uint <ref> :> columnSizePtr
|
||||||
0 short <ref> :> decimalDigitsPtr
|
0 short <ref> :> decimalDigitsPtr
|
||||||
0 short <ref> :> nullablePtr
|
0 short <ref> :> nullablePtr
|
||||||
statement columnNumber columnName bufferLen nameLengthPtr
|
statement columnNumber columnName bufferLen nameLengthPtr
|
||||||
dataTypePtr columnSizePtr decimalDigitsPtr nullablePtr
|
dataTypePtr columnSizePtr decimalDigitsPtr nullablePtr
|
||||||
SQLDescribeCol succeeded? [
|
SQLDescribeCol succeeded? [
|
||||||
nullablePtr short deref
|
nullablePtr short deref
|
||||||
decimalDigitsPtr short deref
|
decimalDigitsPtr short deref
|
||||||
columnSizePtr uint deref
|
columnSizePtr uint deref
|
||||||
dataTypePtr short deref convert-sql-type
|
dataTypePtr short deref convert-sql-type
|
||||||
columnName ascii alien>string
|
columnName ascii alien>string
|
||||||
columnNumber <column>
|
columnNumber <column>
|
||||||
] [
|
] [
|
||||||
"odbc-describe-column failed" throw
|
"odbc-describe-column failed" throw
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: dereference-type-pointer ( byte-array column -- object )
|
: dereference-type-pointer ( byte-array column -- object )
|
||||||
type>> {
|
type>> {
|
||||||
{ SQL-CHAR [ ascii alien>string ] }
|
{ SQL-CHAR [ ascii alien>string ] }
|
||||||
{ SQL-VARCHAR [ ascii alien>string ] }
|
{ SQL-VARCHAR [ ascii alien>string ] }
|
||||||
{ SQL-LONGVARCHAR [ ascii alien>string ] }
|
{ SQL-LONGVARCHAR [ ascii alien>string ] }
|
||||||
{ SQL-WCHAR [ ascii alien>string ] }
|
{ SQL-WCHAR [ ascii alien>string ] }
|
||||||
{ SQL-WCHARVAR [ ascii alien>string ] }
|
{ SQL-WCHARVAR [ ascii alien>string ] }
|
||||||
{ SQL-WLONGCHARVAR [ ascii alien>string ] }
|
{ SQL-WLONGCHARVAR [ ascii alien>string ] }
|
||||||
{ SQL-SMALLINT [ short deref ] }
|
{ SQL-SMALLINT [ short deref ] }
|
||||||
{ SQL-INTEGER [ long deref ] }
|
{ SQL-INTEGER [ long deref ] }
|
||||||
{ SQL-REAL [ float deref ] }
|
{ SQL-REAL [ float deref ] }
|
||||||
{ SQL-FLOAT [ double deref ] }
|
{ SQL-FLOAT [ double deref ] }
|
||||||
{ SQL-DOUBLE [ double deref ] }
|
{ SQL-DOUBLE [ double deref ] }
|
||||||
{ SQL-TINYINT [ char deref ] }
|
{ SQL-TINYINT [ char deref ] }
|
||||||
{ SQL-BIGINT [ longlong deref ] }
|
{ SQL-BIGINT [ longlong deref ] }
|
||||||
[ nip [ "Unknown SQL Type: " % name>> % ] "" make ]
|
[ nip [ "Unknown SQL Type: " % name>> % ] "" make ]
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
TUPLE: field value column ;
|
TUPLE: field value column ;
|
||||||
|
|
||||||
C: <field> field
|
C: <field> field
|
||||||
|
|
||||||
:: odbc-get-field ( statement column! -- field )
|
:: odbc-get-field ( statement column! -- field )
|
||||||
column column? [ statement column odbc-describe-column column! ] unless
|
column column? [
|
||||||
8192 :> bufferLen
|
statement column odbc-describe-column column!
|
||||||
bufferLen alien-space-str :> targetValuePtr
|
] unless
|
||||||
statement column number>> SQL-C-DEFAULT
|
8192 :> bufferLen
|
||||||
targetValuePtr bufferLen f SQLGetData succeeded? [
|
bufferLen alien-space-str :> targetValuePtr
|
||||||
targetValuePtr column [ dereference-type-pointer ] keep <field>
|
statement column number>> SQL-C-DEFAULT
|
||||||
] [
|
targetValuePtr bufferLen f SQLGetData
|
||||||
column [
|
succeeded? [
|
||||||
"SQLGetData Failed for Column: " %
|
targetValuePtr column [ dereference-type-pointer ] keep <field>
|
||||||
dup name>> %
|
] [
|
||||||
" of type: " % dup type>> name>> %
|
column [
|
||||||
] "" make swap <field>
|
"SQLGetData Failed for Column: " %
|
||||||
] if ;
|
dup name>> %
|
||||||
|
" of type: " % dup type>> name>> %
|
||||||
|
] "" make swap <field>
|
||||||
|
] if ;
|
||||||
|
|
||||||
: odbc-get-row-fields ( statement -- seq )
|
: odbc-get-row-fields ( statement -- seq )
|
||||||
[
|
[
|
||||||
dup odbc-number-of-columns [
|
dup odbc-number-of-columns [
|
||||||
1 + odbc-get-field value>> ,
|
1 + odbc-get-field value>> ,
|
||||||
] with each
|
] with each
|
||||||
] { } make ;
|
] { } make ;
|
||||||
|
|
||||||
: (odbc-get-all-rows) ( statement -- )
|
: (odbc-get-all-rows) ( statement -- )
|
||||||
dup odbc-next-row [ dup odbc-get-row-fields , yield (odbc-get-all-rows) ] [ drop ] if ;
|
dup odbc-next-row [
|
||||||
|
dup odbc-get-row-fields , yield (odbc-get-all-rows)
|
||||||
|
] [
|
||||||
|
drop
|
||||||
|
] if ;
|
||||||
|
|
||||||
: odbc-get-all-rows ( statement -- seq )
|
: odbc-get-all-rows ( statement -- seq )
|
||||||
[ (odbc-get-all-rows) ] { } make ;
|
[ (odbc-get-all-rows) ] { } make ;
|
||||||
|
|
||||||
: odbc-query ( string dsn -- result )
|
: odbc-query ( string dsn -- result )
|
||||||
odbc-init swap odbc-connect [
|
odbc-init swap odbc-connect [
|
||||||
swap odbc-prepare
|
swap odbc-prepare
|
||||||
dup odbc-execute
|
dup odbc-execute
|
||||||
dup odbc-get-all-rows
|
dup odbc-get-all-rows
|
||||||
swap odbc-free-statement
|
swap odbc-free-statement
|
||||||
] keep odbc-disconnect ;
|
] keep odbc-disconnect ;
|
||||||
|
|
Loading…
Reference in New Issue