| Previous | Next
ODBC Extension for Win32Contents:Win32::ODBC allows you to make a connection to a database that supports ODBC under both Win32 and Unix. Win32::ODBC allows you to support as many ODBC connections as are allowed by memory and ODBC. Generally, you'll use Win32::ODBC to access databases such as those created under Microsoft Access, but there's also an ODBC driver available for MySQL if you want to connect to MySQL via ODBC and aren't able to use DBI and a DBD. To get started, you'll need to use use Win32::ODBC; my $dsn = "DSN=Name of Database;UID=Your UID Here;PWD=dbpasswd;" my $DB = Win32::ODBC->new($dsn); ODBC Methods and PropertiesOnce you have created an ODBC object, you can use its methods or adjust its properties as you require. ODBC methods are implemented as you'd expect with the Perl object syntax. The following methods are defined by Win32::ODBC.
$obj->Catalog(qualifier, owner, name, type) Tells ODBC to create a data set that contains table information about the DSN. Use Fetch and Data or DataHash to retrieve the data. The returned format is: [
Win32::ODBC->ColAttributes(attributes, [field_names]) Returns the attributes
Win32::ODBC->ConfigDSN(option, driver, attribute1 [, attribute2, attribute3, ... ]) Configures a DSN.
Win32::ODBC->Connection( ) Returns the connection number associated with the ODBC connection.
Win32::ODBC->Close( ) Closes the ODBC connection. No return value.
Win32::ODBC->Data([field_name]) Returns the contents of column name
Win32::ODBC->DataHash([field1, field2, ...]) Returns the contents for
Win32::ODBC->DataSources( ) Returns an associative array of data sources and ODBC remarks about them. They are returned in the form of:
Win32::ODBC->Debug( [ 0 | 1 ] ) Sets the debug option to on or off. If nothing is specified, then nothing is changed. Returns the debugging value ( or ).
Win32::ODBC->Drivers( ) Returns an associative array of ODBC Drivers and their attributes. They are returned in the form of:
in which driver is the ODBC driver name, and
Win32::ODBC->DropCursor([close_type]) Drops the cursor associated with the ODBC object. This forces the cursor to be deallocated. This overrides
Win32::ODBC->DumpData( ) Dumps to the screen the fieldnames and all records of the current data set. Used primarily for debugging. No return value.
Win32::ODBC->Error( ) Returns the last encountered error. The returned value is context-dependent. If called in a scalar context, then a three-element array is returned: ( If called in a string context, then a string is returned: "[error_number] [connection_number] [error_text]" If debugging is on, then two more variables are returned: ( ..., function, level ) function is the name of the function in which the error occurred, and
Win32::ODBC->FetchRow(row, [type]) Retrieves the next record from the keyset. When
Win32::ODBC->FieldNames( ) Returns an array of fieldnames found in the current data set. The order isn't specified.
Win32::ODBC->GetConnections( ) Returns an array of connection numbers showing which connections are currently open.
Win32::ODBC->GetConnectOption(option) Returns the value of the specified connect option
Win32::ODBC->GetCursorName( ) Returns the name of the current cursor as a string or
Win32::ODBC->GetData( ) Retrieves the current row from the dataset. This is not generally used by users; it is used internally. Returns an array of field data in which the first element is either false (if successful) or true (if not successful).
Win32::ODBC->getDSN([dsn]) Returns an associative array indicating the configuration for the specified
Win32::ODBC->GetFunctions([function1, function2]) Returns an associative array indicating the ability of the ODBC Driver to support the specified functions. If no functions are specified, then a 100-element associative array is returned containing all possible functions and their values.
For example:
Win32::ODBC->GetInfo([option]) Returns a string indicating the value of the particular option specified.
Win32::ODBC->GetMaxBufSize( ) Returns the current allocated limit for MaxBufSize. For more info, see SetMaxBufSize.
Win32::ODBC->GetSQLState( ) Returns a string indicating the SQL state as reported by ODBC. The SQL state is a code that the ODBC Manager or ODBC Driver returns after the execution of a SQL function. This is helpful for debugging purposes.
Win32::ODBC->GetStmtCloseType([connection]) Returns a string indicating the type of closure that will be used every time the hstmt is freed. (See
Win32::ODBC->GetStmtOption([option]) Returns the value of the specified statement option
Win32::ODBC->MoreResults([connection]) Reports whether there is data yet to be retrieved from the query. This can happen if the query was a multiple select: "SELECT * FROM [foo] SELECT * FROM [bar]" Returns if there is more data,
Win32::ODBC->RowCount([connection]) For UPDATE, INSERT, and DELETE statements, the returned value is the number of rows affected by the request, or
Win32::ODBC->Run(sql) Executes the SQL command
Win32::ODBC->SetConnectOption(option) Sets the value of the specified connect option
Win32::ODBC->SetCursorName(name) Sets the name of the current cursor. Returns true on success, false otherwise.
Win32::ODBC->SetPos(row, [option, lock]) Moves the cursor to the row
Win32::ODBC->SetMaxBufSize(size) Sets the MaxBufSize for a particular connection. The amount of memory allocated to retrieve the field data of a record is dynamic and changes when it needs to be larger. Returns the maximum number of bytes.
Win32::ODBC->SetStmtCloseType(type, [connection]) Sets a particular hstmt close type for the connection. This is the same as SQL_CLOSE SQL_DROP SQL_UNBIND SQL_RESET_PARAMS Returns a string indicating the newly set type.
Win32::ODBC->SetStmtOption(option) Sets the value of the specified statement option
Win32::ODBC->Shutdown( ) Closes the ODBC connection and dumps to the screen info about it. Used primarily for debugging. No return value.
Win32::ODBC->Sql(SQL_STRING) Executes the SQL command
Win32::ODBC->TableList(qualifier, owner, name, type) Returns the catalog of tables available in the DSN. For an unknown parameter, just specify the empty string "". Returns an array of table names.
Win32::ODBC->Transact(type) Forces the ODBC connection to perform a rollback or commit transaction. SQL_COMMIT SQL_ROLLBACK Returns true on success, false otherwise.
Win32::ODBC->Version(packages) Returns an array of version numbers for the requested packages (ODBC.pm or ODBC.PLL). If the list |