ODBC(3)
π ODBC(3) π
from User Contributed Perl Documentation β bestie, we're doing the DBD::ODBC glow-up. π
π NAME π
DBD::ODBC β ODBC Driver for DBI. Periodt. β¨
β VERSION β
This documentation refers to DBD::ODBC version 1.61.
π¨ WARNING π¨
Okay so this version of DBD::ODBC contains a significant fix to unicode when inserting into CHAR/VARCHAR columns and it is a change in behaviour from 1.45. The change only applies to unicode builds of DBD::ODBC (the default on Windows but you can build it for unicode on unix too) and char/varchar columns and not nchar/nvarchar columns.
Prior to this release of DBD::ODBC when you are using the unicode build of DBD::ODBC and inserted data into a CHAR/VARCHAR columns using parameters DBD::ODBC did this:
- if you set
odbc_describe_parametersto0, (thus preventing DBD::ODBC from callingSQLDescribeParam) parameters for CHAR/VARCHAR columns were bound asSQL_WVARCHARorSQL_WLONGVARCHAR(depending on the length of the parameter). - if you set
odbc_force_bind_typethen all parameters are bound as you specified. - if you override the parameter type in the
bind_parammethod, the type you specified would be used. - if the driver does not support
SQLDescribeParamorSQLDescribeParamwas called and failed then the bind type defaulted as in1. - if none of the above (and I'd guess that is the normal case for most people) then DBD::ODBC calls
SQLDescribeParamto find the parameter type. This usually returnsSQL_CHARorSQL_VARCHARfor CHAR/VARCHAR columns unsurprisingly. The parameter was then bound asSQL_VARCHAR.
Items 1 to 4 still apply. 5 now has a different behaviour. In this release, DBD::ODBC now looks at your bound data first before using the type returned by SQLDescribeParam. If your data looks like unicode (i.e., SvUTF8() is true) it now binds the parameter as SQL_WVARCHAR.
What might this might mean to you? π
If you had Perl scalars that were bound to CHAR/VARCHAR columns in an insert/update/delete and those scalars contained unicode, DBD::ODBC would actually pass the individual octets in your scalar not characters. For instance, if you had the Perl scalar "\x{20ac}" (the Euro unicode character) and you bound it to a CHAR/VARCHAR, DBD::ODBC would pass 0xe2, 0x82, 0xc2 as separate characters because those bytes were Perl's UTF-8 encoding of a euro. These would probably be interpreted by your database engine as 3 characters in its current codepage. If you queried your database to find the length of the data inserted you'd probably get back 3, not 1.
However, when DBD::ODBC read that column back in a select statement, it would bind the column as SQL_WCHAR and you'd get back 3 characters with the utf8 flag on (what those characters were depends on how your database or driver translates code page characters to wide characters).
What should happen now is that if your bound parameters are unicode, DBD::ODBC will bind them as wide characters (unicode) and your driver or database will attempt to convert them into the code page it is using. This means so long as your database can store the data you are inserting, when you read it back you should get what you inserted. π
π¦ SYNOPSIS π¦
use DBI;
$dbh = DBI->connect('dbi:ODBC:DSN=mydsn', 'user', 'password');
See DBI for more information.
πΈ DESCRIPTION πΈ
π Change log and FAQs π
Please note that the change log has been moved to DBD::ODBC::Changes. To access this documentation, use perldoc DBD::ODBC::Changes.
The FAQs have also moved to DBD::ODBC::FAQ.pm. To access the FAQs use perldoc DBD::ODBC::FAQ.
π§ͺ Important note about the tests π§ͺ
DBD::ODBC is unlike most other DBDs in that it connects to literally dozens of possible ODBC Drivers. It is practically impossible for me to test every one and so some tests may fail with some ODBC Drivers. This does not mean DBD::ODBC will not work with your ODBC Driver but it is worth reporting any test failures on rt.cpan.org or to the dbi-users mailing list.
π§ DBI attribute handling π§
If a DBI defined attribute is not mentioned here it behaves as per the DBI specification.
π ReadOnly (boolean) π
DBI documents the ReadOnly attribute as being settable and retrievable on connection and statement handles. In ODBC setting ReadOnly to true causes the connection attribute SQL_ATTR_ACCESS_MODE to be set to SQL_MODE_READ_ONLY and setting it to false will set the access mode to SQL_MODE_READ_WRITE (which is the default in ODBC).
Note: There is no equivalent of setting ReadOnly on a statement handle in ODBC.
Note: See ODBC documentation onSQL_ATTR_ACCESS_MODEas setting it toSQL_MODE_READ_ONLYdoes not prevent your script from running updates or deletes; it is simply a hint to the driver/database that you won't be doing updates.
Note: SinceDBD::ODCB1.44_3, if the driver does not support settingSQL_ATTR_ACCESS_MODEand returnsSQL_SUCCESS_WITH_INFOand"option value changed"a warning is issued (which you'll only see if you have DBI >1.628). In addition, any subsequent attempts to fetch theReadOnlyattribute will return the value last set.
This attribute requires DBI version 1.55 or better.
π¦ Private attributes common to connection and statement handles π¦
π odbc_ignore_named_placeholders π
Use this if you have special needs (such as Oracle triggers, etc) where :new or :name mean something special and are not just place holder names. You must then use ? for binding parameters. Example:
$dbh->{odbc_ignore_named_placeholders} = 1;
$dbh->do("create trigger foo as if :new.x <> :old.x then ... etc");
Without this, DBD::ODBC will think :new and :old are placeholders for binding and get confused.
π odbc_default_bind_type π
This value defaults to 0.
Older versions of DBD::ODBC assumed that the parameter binding type was 12 ("SQL_VARCHAR"). Newer versions always attempt to call SQLDescribeParam to find the parameter types but if SQLDescribeParam is unavailable DBD::ODBC falls back to a default bind type. The internal default bind type is SQL_VARCHAR (for non-unicode build) and SQL_WVARCHAR or SQL_VARCHAR (for a unicode build depending on whether the parameter is unicode or not). If you set odbc_default_bind_type to a value other than 0 you override the internal default.
N.B If you call the bind_param method with a SQL type this overrides everything else above.
π odbc_force_bind_type π
This value defaults to 0.
If set to anything other than 0 this will force bound parameters to be bound as this type and SQLDescribeParam will not be used; in other words it implies odbc_describe_parameters is set to false too.
Older versions of DBD::ODBC assumed the parameter binding type was 12 ("SQL_VARCHAR") and newer versions always attempt to call SQLDescribeParam to find the parameter types. If your driver supports SQLDescribeParam and it succeeds it may still fail to describe the parameters accurately (MS SQL Server sometimes does this with some SQL like select myfunc(?) where 1 = 1). Setting odbc_force_bind_type to SQL_VARCHAR will force DBD::ODBC to bind all the parameters as SQL_VARCHAR and ignore SQLDescribeParam.
Bear in mind that if you are inserting unicode data you probably want to use SQL_WVARCHAR/SQL_WCHAR/SQL_WLONGVARCHAR and not SQL_VARCHAR.
As this attribute was created to work around buggy ODBC Drivers which support SQLDescribeParam but describe the parameters incorrectly you are probably better specifying the bind type on the bind_param call on a per statement level rather than blindly setting odbc_force_bind_type across a whole connection.
N.B If you call the bind_param method with a SQL type this overrides everything else above.
π odbc_force_rebind π
This is to handle special cases, especially when using multiple result sets. Set this before execute to "force" DBD::ODBC to re-obtain the result set's number of columns and column types for each execute. Especially useful for calling stored procedures which may return different result sets each execute. The only performance penalty is during execute(), but I didn't want to incur that penalty for all circumstances. It is probably fairly rare that this occurs. This attribute will be automatically set when multiple result sets are triggered. Most people shouldn't have to worry about this.
π odbc_async_exec π
Allow asynchronous execution of queries. This causes a spin-loop (with a small sleep) until the ODBC API being called is complete (i.e., while the ODBC API returns SQL_STILL_EXECUTING). This is useful, however, if you want the error handling and asynchronous messages (see the odbc_err_handler and t/20SQLServer.t for an example of this).
π odbc_query_timeout π
This allows you to change the ODBC query timeout (the ODBC statement attribute SQL_ATTR_QUERY_TIMEOUT). ODBC defines the query time out as the number of seconds to wait for a SQL statement to execute before returning to the application. A value of 0 (the default) means there is no time out. Do not confuse this with the ODBC attributes SQL_ATTR_LOGIN_TIMEOUT and SQL_ATTR_CONNECTION_TIMEOUT. Add
{ odbc_query_timeout => 30 }
to your connect, set on the dbh before creating a statement or explicitly set it on your statement handle. The odbc_query_timeout on a statement is inherited from the parent connection.
Note that internally DBD::ODBC only sets the query timeout if you set it explicitly and the default of 0 (no time out) is implemented by the ODBC driver and not DBD::ODBC.
Note that some ODBC drivers implement a maximum query timeout value and will limit timeouts set above their maximum. You may see a warning if your time out is capped by the driver but there is currently no way to retrieve the capped value back from the driver.
Note that some drivers may not support this attribute.
See t/20SqlServer.t for an example.
π odbc_putdata_start π
odbc_putdata_start defines the size at which DBD::ODBC uses SQLPutData and SQLParamData to send larger objects to the database instead of simply binding them as normal with SQLBindParameter. It is mostly a placeholder for future changes allowing chunks of data to be sent to the database and there is little reason for anyone to change it currently.
The default for odbc_putdata_start is 32768 because this value was hard-coded in DBD::ODBC until 1.16_1.
π odbc_column_display_size π
If your ODBC driver does not support the SQL_COLUMN_DISPLAY_SIZE and SQL_COLUMN_LENGTH attributes to SQLColAtrributes then DBD::ODBC does not know how big the column might be. odbc_column_display_size sets the default value for the column size when retrieving column data where the size cannot be determined.
The default for odbc_column_display_size is 2001 because this value was hard-coded in DBD::ODBC until 1.17_3.
π odbc_utf8_on π
Set this flag and, like, every string the ODBC driver hands back gets treated as UTF-8 encoded β with the exception of columns described as SQL_BINARY or SQL_TIMESTAMP and its variations, those stay as they are, no cap.
Some ODBC drivers (looking at you, Aster, and maybe PostgreSQL) return UTF-8 encoded data but do not support the SQLxxxW unicode API. Turning this flag on makes DBD::ODBC treat the driver's returned data as UTF-8 encoded, and it gets marked as such in Perl. Slay.
π«Ά Do not confuse this with DBD::ODBC's unicode support, bestie. The odbc_utf8_on attribute only applies to non-unicode enabled builds of DBD::ODBC. Two totally different vibes.
odbc_describe_parameters
Defaults to on. When it's set, DBD::ODBC is allowed to call SQLDescribeParam (if your driver supports it, that is) to go get info about any parameters. Iconic little fact-finding mission.
When it's off/false, DBD::ODBC will not call SQLDescribeParam and instead defaults to binding parameters as SQL_CHAR/SQL_WCHAR β depends on the build type and whether your data is unicode or not.
And listen: you do not have to disable odbc_describe_parameters just because your driver doesn't support SQLDescribeParam β DBD::ODBC works that out at the start via SQLGetFunctions all by itself. It's giving self-sufficient.
β οΈ Note: disablingodbc_describe_parameterswhen your driver does supportSQLDescribeParammay prevent DBD::ODBC from binding parameters properly for some column types. So like, be careful.
You can also set this attribute in the attributes you pass to the prepare method. Flexible queen.
Why does this attribute even exist? Real talk: it was added so someone moving from freeTDS (a driver which does not support SQLDescribeParam) to a driver which does support SQLDescribeParam could do so without changing any Perl. The situation was very specific β dates were being bound as dates when SQLDescribeParam was called, and chars without, and the data format was not a supported date format. Messy, but handled. π
π«Ά Private methods common to connection and statement handles π«Ά
odbc_getdiagrec
@diags = $handle->odbc_getdiagrec($record_number);
Introduced in 1.34_3.
This is just a little wrapper around the ODBC API SQLGetDiagRec. When a method on a connection or statement handle fails and there are any ODBC diagnostics hanging around, you can use this method to retrieve them. Records start at 1 and there may be more than 1 β there can absolutely be a whole squad of them.
It returns an array containing the state, native and error message text, or an empty array if the requested diagnostic record does not exist. To get all the diagnostics available, just keep incrementing $record_number until odbc_getdiagrec returns an empty array. Keep going till it ghosts you. π
All of the state, native and message text are already passed to DBI via its set_err method, so this method doesn't really tell you anything you can't already get from DBI β except when there's more than one diagnostic. That's the moment it eats.
You may find this useful in an error handler, since you can get the ODBC diagnostics as they are, and not how DBD::ODBC was forced to fit them into the DBI's system.
β οΈ NOTE: calling this method does not clear DBI's error values the way that usually happens. Just so you know.
odbc_getdiagfield
$diag = $handle->odbc_getdiagfield($record, $identifier);
This is just a little wrapper around the ODBC API SQLGetDiagField. When a method on a connection or statement handle fails and there are any ODBC diagnostics, you can use this method to retrieve the individual diagnostic fields. As with odbc_getdiagrec, records start at 1. The identifier is one of:
SQL_DIAG_CURSOR_ROW_COUNT
SQL_DIAG_DYNAMIC_FUNCTION
SQL_DIAG_DYNAMIC_FUNCTION_CODE
SQL_DIAG_NUMBER
SQL_DIAG_RETURNCODE
SQL_DIAG_ROW_COUNT
SQL_DIAG_CLASS_ORIGIN
SQL_DIAG_COLUMN_NUMBER
SQL_DIAG_CONNECTION_NAME
SQL_DIAG_MESSAGE_TEXT
SQL_DIAG_NATIVE
SQL_DIAG_ROW_NUMBER
SQL_DIAG_SERVER_NAME
SQL_DIAG_SQLSTATE
SQL_DIAG_SUBCLASS_ORIGIN
DBD::ODBC exports these constants as 'diags', like so:
use DBD::ODBC qw(:diags);
Of particular interest is SQL_DIAG_COLUMN_NUMBER β because it will tell you which bound column or parameter is in error (assuming your driver supports it, of course). See params_in_error in the examples dir. So handy. β¨
β οΈ NOTE: calling this method does not clear DBI's error values the way that usually happens. Yeah, same warning, it's a whole thing.
π Private connection attributes π
odbc_err_handler
π NOTE: you might want to look at DBI's error handler before using the one in DBD::ODBC β however, there are subtle differences. DBD::ODBC'sodbc_err_handleris called for error and informational diagnostics, i.e., it's called when an ODBC call fails theSQL_SUCCEEDEDmacro, which means the ODBC call returnedSQL_ERROR(-1) orSQL_SUCCESS_WITH_INFO(1).
This lets error and informational diagnostics be handled by the application. Basically a call-back function, supplied by the application, to handle or ignore messages. Main character energy for your error handling.
The callback function receives four parameters: state (string), error (string), native error code (number) and the status returned from the last ODBC API. That fourth argument was added in 1.30_7.
If the error handler returns 0, the error is ignored. Otherwise, the error is passed through the normal DBI error handling. Note that if the status is SQL_SUCCESS_WITH_INFO, this will not reach the DBI error handler, because it is not an error. It's just, like, info.
This can also be used for procedures under MS SQL Server (Sybase too, probably) to obtain messages from system procedures such as DBCC. Check t/20SQLServer.t and t/10handler.t.
$dbh->{RaiseError} = 1;
sub err_handler {
($state, $msg, $native, $rc, $status) = @_;
if ($state = '12345')
return 0; # ignore this error
else
return 1; # propagate error
}
$dbh->{odbc_err_handler} = \&err_handler;
# do something to cause an error
$dbh->{odbc_err_handler} = undef; # cancel the handler
odbc_SQL_ROWSET_SIZE
Setting odbc_SQL_ROWSET_SIZE results in a call to SQLSetConnectAttr to set the ODBC SQL_ROWSET_SIZE (9) attribute to whatever value you set odbc_SQL_ROWSET_SIZE to. Set it, it sets it. Simple as.
The ODBC default for SQL_ROWSET_SIZE is 1.
Usually MS SQL Server does not support multiple active statements (MAS), i.e., you cannot have 2 or more outstanding selects. You can set odbc_SQL_ROWSET_SIZE to 2 to persuade MS SQL Server to support multiple active statements. Sweet-talk it. π
Setting SQL_ROWSET_SIZE usually only affects calls to SQLExtendedFetch β but it does allow MAS, and since DBD::ODBC does not use SQLExtendedFetch, there should be no ill effects to DBD::ODBC. We stay unbothered.
π Be careful with this attribute: once set to anything larger than 1 (the default), you must retrieve all result-sets before the statement handle goes out of scope, or you can upset the TDS protocol and this can result in a hang. With DBI this is unlikely, as DBI warns when a statement goes out of scope with outstanding results. Still β don't test fate.
β οΈ NOTE: if you get an error saying"[Microsoft][ODBC SQL Server Driver]Invalid attribute/option identifier (SQL-HY092)"when you setodbc_SQL_ROWSET_SIZEin the connect method, you need to either a) upgrade to DBI1.616or above, or b) setodbc_SQL_ROWSET_SIZEafter connect.
In versions of SQL Server 2005 and later, see "Multiple Active Statements (MAS)" in the DBD::ODBC::FAQ instead of using this attribute.
Thanks to Andrew Brown for the original patch. π«Ά
DBD developer note: here lies a bag of worms. πͺ± Firstly, SQL_ROWSET_SIZE is an ODBC 2 attribute and is usually a statement attribute, not a connection attribute. However, in ODBC 2.0 you could set statement attributes on a connection handle and it acted as a default for all subsequent statement handles created under that connection handle. If you're using ODBC 3, the driver manager continues to map this call, but the ODBC Driver needs to act on it (the MS SQL Server driver still appears to, but some other ODBC drivers for MS SQL Server do not). Secondly, somewhere along the line MS decided it was no longer valid to retrieve the SQL_ROWSET_SIZE attribute from a connection handle in an ODBC 3 application (which DBD::ODBC now is). In itself, this would not be a problem, except for a minor bug in DBI which until release 1.616 mistakenly issued a FETCH on any attribute mentioned in the connect method call. As a result, if you use a DBI prior to 1.616 and attempt to set odbc_SQL_ROWSET_SIZE in the connect method call, DBI issues a FETCH on odbc_SQL_ROWSET_SIZE and the driver manager throws it out as an invalid attribute, thus resulting in an error. The only way around this (other than upgrading DBI) is to set odbc_SQL_ROWSET_SIZE AFTER the call to connect. Thirdly, MS withdrew the SQLROWSETSIZE macro from the sql header files in MDAC 2.7 for 64 bit platforms, i.e., SQLROWSETSIZE is not defined on 64 bit platforms from MDAC 2.7 as it is in a "#ifdef win32" (see http://msdn.microsoft.com/en-us/library/ms716287%28v=vs.85%29.aspx). Setting SQL_ROWSET_SIZE still seems to take effect on 64 bit platforms, but you can no longer retrieve its value from a connection handle (hence the issue above with DBI redundant FETCH). A whole saga, honestly. π
odbc_exec_direct
Force DBD::ODBC to use "SQLExecDirect" instead of "SQLPrepare"/"SQLExecute". Switching up the whole flow.
There are drivers that only support "SQLExecDirect", and the DBD::ODBC do() override does not allow returning result sets. Therefore, the way to do this now is to set the attribute odbc_exec_direct. Periodt.
π NOTE: you may also want to use this option if you're creating temporary objects (e.g., tables) in MS SQL Server and for some reason cannot use the"do"method. Seehttp://technet.microsoft.com/en-US/library/ms131667.aspx, which says Prepared statements cannot be used to create temporary objects on SQL Server 2000 or later.... Withoutodbc_exec_direct, the temporary object will disappear before you can use it. It literally vanishes. π¦
There are currently two ways to get this:
$dbh->prepare($sql, { odbc_exec_direct => 1});
and
$dbh->{odbc_exec_direct} = 1;
β οΈ NOTE: even if you build DBD::ODBC with unicode support, you still cannot pass unicode strings to thepreparemethod if you also setodbc_exec_direct. This is a restriction in this attribute which is unavoidable. She said what she said. π
odbc_SQL_DRIVER_ODBC_VER
This, while available via get_info(), is captured here. I may get rid of this as I only used it for debugging purposes. Lowkey just hanging out. π
odbc_cursortype
This allows multiple concurrent statements on SQL*Server. In your connect, add
{ odbc_cursortype => 2 }.
If you're using DBI > 1.41, you should also be able to use
{ odbc_cursortype => DBI::SQL_CURSOR_DYNAMIC }
instead. Fancy. For example:
my $dbh = DBI->connect("dbi:ODBC:$DSN", $user, $pass,
{ RaiseError => 1, odbc_cursortype => 2});
my $sth = $dbh->prepare("one statement");
my $sth2 = $dbh->prepare("two statement");
$sth->execute;
my @row;
while (@row = $sth->fetchrow_array) {
$sth2->execute($row[0]);
}
See t/20SqlServer.t for an example.
In versions of SQL Server 2005 and later, see "Multiple Active Statements (MAS)" in the DBD::ODBC::FAQ instead of using this attribute. Same energy as before β go read the FAQ. π
Like, it's a read-only attribute β look, don't touch, bestie β and it tells you whether DBD::ODBC got built with the C macro WITH_UNICODE or not. Value of 1? Slay, it was built with WITH_UNICODE. Value of 0? Nope, it wasn't. That's the whole vibe check.
Why do you even care? Because building with WITH_UNICODE changes up columns and parameters that are SQL_C_WCHAR, SQL_WCHAR, SQL_WVARCHAR, and SQL_WLONGVARCHAR, plus SQL, plus the connect method, plus a whole lot more. Go peek at "Unicode" for the full tea.
When odbc_has_unicode is 1, DBD::ODBC will:
- bind all string columns as wide characters (
SQL_Wxxx) β which means UNICODE data stored in those columns comes back to Perl correctly as unicode (i.e. encoded in UTF-8, with the UTF-8 flag set). Obsessed. - bind parameters the database declares as wide characters or unicode parameters as
SQL_Wxxxβ so any parameter where the database says it's a wide character, or where the parameter data is unicode, or where the parameter type is explicitly set to a wide type (e.g.SQL_Wxxx), gets bound as wide characters in the ODBC API, and DBD::ODBC encodes the perl parameters as UTF-16 before handing them to the driver. - SQL β SQL passed to the
prepareordomethods that has the UTF-8 flag set gets converted to UTF-16 before being passed to the ODBC APIsSQLPrepareorSQLExecDirect. - connection strings β connection strings passed to the
connectmethod get converted to UTF-16 before being passed to the ODBC APISQLDriverConnectW. And this happens irrespective of whether the UTF-8 flag is set on the perl connect strings, because unixODBC requires an application to callSQLDriverConnectWto signal that it'll be calling the wide ODBC APIs. Rules are rules.
NOTE: You'll need at least Perl 5.8.1 to use UNICODE with DBD::ODBC. No ancient-Perl nonsense, please. π
NOTE: Binding of unicode output parameters is coded but untested. Like, the code is there, nobody's stress-tested the poor thing. π
NOTE: When building DBD::ODBC on Windows ($^O eq 'MSWin32') theWITH_UNICODEmacro is automatically added. To disable it, specify-nouas an argument toMakefile.PL(e.g.perl Makefile.PL -nou). On non-Windows platforms theWITH_UNICODEmacro is not enabled by default, and to enable it you need to specify the-uargument toMakefile.PL. Please bear in mind that some ODBC drivers do not supportSQL_Wxxxcolumns or parameters β so check before you commit, fr fr.
You can also specify that you want UNICODE support by setting the DBD_ODBC_UNICODE environment variable prior to install:
export DBD_ODBC_UNICODE=1
cpanm DBD::ODBC
UNICODE support in ODBC Drivers differs considerably. Please read the README.unicode file for further details. It's giving "required reading", sorry. π
π odbc_out_connect_string
After calling the connect method this will be the ODBC driver's out connection string β see the documentation on SQLDriverConnect.
NOTE: this value is only set if DBD::ODBC calls theSQLDriverConnectODBC API (and notSQLConnect), which only happens if a)DSNorDRIVERis specified in the connection string or b)SQLConnectfails. So like, conditional queen. π
Typically, applications (like MS Access and many others) which build a connection string via dialogs and possibly SQLBrowseConnect eventually end up with a successful ODBC connection to the ODBC driver and database. The odbc_out_connect_string provides a string which you can pass to SQLDriverConnect (DBI's connect prefixed with dbi:ODBC:) which will connect you to the same datasource at a later date. You may also want to see "odbc_driver_complete". Reusable connection string = main character energy. β¨
π¦ odbc_version
This was added prior to the move to ODBC 3.x to allow the caller to "force" ODBC 3.0 compatibility. It's probably not as useful now, but it allowed get_info and get_type_info to return correct/updated information that ODBC 2.x didn't permit/provide. Since DBD::ODBC is now 3.x, this can be used to force 2.x behavior via something like:
my $dbh = DBI->connect("dbi:ODBC:$DSN", $user, $pass,
{ odbc_version =>2});
πΈ odbc_driver_complete
This attribute was added to DBD::ODBC in 1.32_2. Hi, vintage. π
odbc_driver_complete is only relevant to the Windows operating system and will be ignored on other platforms. It is off by default.
When set to a true value DBD::ODBC attempts to obtain a window handle and calls SQLDriverConnect with the SQL_DRIVER_COMPLETE attribute instead of the normal SQL_DRIVER_NOPROMPT option. What this means is that if the connection string does not describe sufficient attributes to enable the ODBC driver manager to connect to a data source, it will throw a dialogue allowing you to input the remaining attributes. Once you ok that dialogue the ODBC Driver Manager will continue as if you specified those attributes in the connection string. Once the connection is complete you may want to look at the odbc_out_connect_string attribute to obtain a connection string you can use in the future to pass into the connect method without prompting. Pop-up does the work, string does the remembering. π«Ά
As a window handle is passed to SQLDriverConnect it also means the ODBC driver may throw a dialogue β e.g., if your password has expired the MS SQL Server driver will often prompt for a new one. Iconic, honestly.
An example is:
my $h = DBI->connect('dbi:ODBC:DRIVER={SQL Server}', "username", "password",
{odbc_driver_complete => 1});
As this only provides the driver and further attributes are required, a dialogue will be thrown allowing you to specify the SQL Server to connect to and possibly other attributes.
π odbc_batch_size
Sets the batch size for execute_for_fetch, which defaults to 10. Bear in mind the bigger you set this the more memory DBD::ODBC will need to allocate when running execute_for_fetch, and the memory required is max_length_of_pn * odbc_batch_size * n_parameters. So like, go big if you want, but your RAM is gonna have opinions. π
π odbc_array_operations
NOTE: this was brieflyodbc_disable_array_operationsin1.35and1.36_1. I did warn it was experimental and it turned out the default was too ambitious and it was a poor name anyway. Also the default was to use array operations and now the default is the opposite.
If set to true DBD::ODBC uses its own internal execute_for_fetch instead of DBI's default execute_for_fetch. The default is false. Using the internal execute_for_fetch should be quite a bit faster when using arrays of parameters for insert/update/delete operations, as batches of parameters are sent to the database in one go. However, the required support in some ODBC drivers is a little sketchy and there is no way for DBD::ODBC to ascertain this until it is too late. Rude, but true. π
Please read the documentation on execute_array and execute_for_fetch, which details subtle differences in DBD::ODBC's implementation compared with using DBI's default implementation. If these differences cause you a problem you can set odbc_array_operations to false and DBD::ODBC will revert to DBI's implementations of the array methods.
You can use the environment variable ODBC_DISABLE_ARRAY_OPERATIONS to switch array operations on/off too. When set to 1 array operations are disabled. When not set the default is used (which currently is off). When set to 0 array operations are used no matter what. I know this is slightly counter intuitive but I've found it difficult to change the name (it got picked up and used in a few places very quickly). Naming is hard, okay?? π
π§ odbc_taf_callback
NOTE: this is experimental until I at least see more than one ODBC driver which supports TAF.
Transparent Application Failover (TAF) is a feature in OCI that allows for clients to automatically reconnect to an instance in the event of a failure of the instance. The reconnect happens automatically from within the OCI (Oracle Call Interface) library.
TAF supports a callback function which, once registered, is called by the driver to let you know what is happening and which allows you, to a degree, to control how the failover is handled.
You need to set up TAF on your instance first and that process is beyond the scope of this document. Once TAF is enabled you simply set odbc_taf_callback to a code reference which should look like this:
sub taf_handler {
my ($dbh, $event, $type) = @_;
# do something here
}
DBD::ODBC will pass the connection handle ($dbh), the Oracle event type (OCI_FO_END, OCI_FO_ABORT, OCI_FO_REAUTH, OCI_FO_BEGIN, OCI_FO_ERROR) and the Oracle type (OCI_FO_NONE, OCI_FO_SESSION, OCI_FO_SELECT, OCI_FO_TXNAL). Consult the Oracle documentation for what these are. You can import these constants using the :taf export tag. If your instance is not TAF enabled it is likely an attempt to register a callback will fail, but this is driver dependent (all DBD::ODBC does is make a SQLSetConnectAttr call and provide a C wrapper which calls your Perl subroutine).
Here is a commented example:
my $h = DBI->connect('dbi:ODBC:oracle','xxx','yyy',
{RaiseError => 1,
odbc_taf_callback => \&taf_handler}) or die "connect";
while (1) {
my $s = $h->selectall_arrayref(q/select 1 from dual/);
sleep 5;
}
sub taf_handler {
my ($dbh, $event, $type) = @_;
#print "taf_handler $dbh, $event, $type\n";
if ($event == OCI_FO_BEGIN) {
print "Instance unavailable, stand by\n";
print "Your TAF type is : ",
($type == OCI_FO_NONE ? "NONE" :
($type == OCI_FO_SESSION ? "SESSION" :
($type == OCI_FO_SELECT ? "SELECT" : "?"))) , "\n";
# start a counter and each time OCI_FO_ERROR is passed in we will
# count down and abort the failover when we hit 0.
$count = 10;
return 0;
} elsif ($event == OCI_FO_ERROR) {
# We get an OCI_FO_ERROR each time the failover fails
# sleep a while until the count hits 0
if (--$count < 1) {
print "Giving up\n";
return 0; # give up
} else {
print "Retrying...\n";
sleep 1;
return OCI_FO_RETRY; # tell Oracle to retry
}
} elsif ($event == OCI_FO_REAUTH) {
print "Failed over user. Resuming Services\n";
} elsif ($event == OCI_FO_END) {
print "Failover ended - resuming\n";
}
return 0;
}
NOTE: The above example is for use with the Easysoft Oracle ODBC Driver. ODBC does not define any standard way of supporting TAF and so different drivers may use different connection attributes to set it up or may even pass the callback different arguments. Unfortunately, I don't have access to any other ODBC driver which supports TAF. Until I see others I cannot create a generic interface. I'll happily accept patches for any other driver or if you send me a working copy of the driver and the documentation I will add support for it. Be the patch you wish to see in the world. π
β odbc_trace_file
Specify the name and path to a file you want ODBC API trace information to be written to. See "odbc_trace".
π₯ odbc_trace
okay so this next bit is literally: enable or disable ODBC API tracing. Set it to 1 to enable and 0 to disable.
This calls SQLSetConnectAttr for SQL_ATTR_TRACE and either sets SQL_OPT_TRACE_ON or SQL_OPT_TRACE_OFF. Enabling tracing tells the ODBC driver manager to write an ODBC API trace to the file named with "odbc_trace_file".
NOTE: If you don't setodbc_trace_filemost ODBC Driver Managers write to a file calledSQL.LOGin the root directory (but this depends on the driver manager used).
NOTE: This tracing is produced by the ODBC Driver Manager and has nothing to do with DBD::ODBC other than it should trace the ODBC calls DBD::ODBC makes, i.e. DBD::ODBC is not responsible for the tracing mechanism itself.
NOTE: Enabling tracing will probably slow your application down a lot. I'd definitely think twice about it if in a production environment unless you are desperate as it tends to produce very large trace files for short periods of ODBC activity.
β¨ Private statement attributes β¨
π¦ odbc_more_results π¦
Use this attribute to determine if there are more result sets available. it's giving "are we done yet or nah?"
Any ODBC Driver which batches results or counts of inserts/updates will need you to loop on odbc_more_results until there are no more results. e.g., if you are performing multiple selects in a procedure or multiple inserts/updates/deletes then you will probably need to loop on odbc_more_results.
Use odbc_more_results as follows:
do {
my @row;
while (@row = $sth->fetchrow_array()) {
# do stuff here
}
} while ($sth->{odbc_more_results});
Note that with multiple result sets and output parameters (i.e., using bind_param_inout), don't expect output parameters to be written to until ALL result sets have been retrieved.
Under the hood this attribute causes a call to the ODBC API SQLMoreResults and then any result set, insert/update/delete or output parameters are described by DBD::ODBC and the statement handle will be ready for processing the new result.
π Private statement methods π
odbc_rows
This method was added in 1.42_1.
In 64 bit ODBC SQLRowCount can return a 64bit value for the number of rows affected. Unfortunately, the DBI DBD interface currently (at least until 1.622) defines execute as returning an int so values which cannot fit in an int are truncated. See RT 81911.
From DBD::ODBC 1.42_1 DBD::ODBC:
- defines this method which will return the affected rows in an IV (and IVs are guaranteed to be able to hold a pointer) so you can get the real affected rows without truncation.
- if it detects an overflow in the execute method it will issue a warning (if
Warnis on which it is by default) and returnINT_MAX.
At some stage DBI may change to fix the issue this works around.
NOTE: the return fromodbc_rowsis not the raw value returned bySQLRowCount. It is the same as execute normally returns e.g.,0E0(for0),-1for unknown andNforNrows affected whereN > 0.
odbc_lob_read
$chrs_or_bytes_read = $sth->odbc_lob_read($column_no, \$lob, $length, \%attr);
Reads $length bytes from the lob at column $column_no returning the lob into $lob and the number of bytes or characters read into $chrs_or_bytes_read. If an error occurs undef will be returned. When there is no more data to be read 0 is returned.
NOTE: This is currently an experimental method and may change in the future e.g., it may support automatic concatenation of the lob parts onto the end of the$lobwith the addition of an extra flag or destination offset as in DBI's undocumentedblob_read.
The type the lob is retrieved as may be overridden in %attr using "TYPE => sql_type". %attr is optional and if omitted defaults to SQL_C_BINARY for binary columns and SQL_C_CHAR/SQL_C_WCHAR for other column types depending on whether DBD::ODBC is built with unicode support. $chrs_or_bytes_read will be the bytes read when the column types SQL_C_CHAR or SQL_C_BINARY are used and characters read if the column type is SQL_C_WCHAR.
When built with unicode support $length specifies the amount of buffer space to be used when retrieving the lob data but as it is returned as SQLWCHAR characters this means you at most retrieve $length/2 characters. When those retrieved characters are encoded in UTF-8 for Perl, the $lob scalar may need to be larger than $length so DBD::ODBC grows it appropriately.
You can retrieve a lob in chunks like this:
$sth->bind_col($column, undef, {TreatAsLOB=>1});
while(my $retrieved = $sth->odbc_lob_read($column, \my $data, $length)) {
print "retrieved=$retrieved lob_data=$data\n";
}
NOTE: to retrieve a lob like this you must first bind the lob column specifyingBindAsLOBor DBD::ODBC will 1) bind the column as normal and it will be subject toLongReadLenand b) failodbc_lob_read.
NOTE: Some database engines and ODBC drivers do not allow you to retrieve columns out of order (e.g., MS SQL Server unless you are using cursors). In those cases you must ensure the lob retrieved is the last (or only) column in your select list.
NOTE: You can retrieve only part of a lob but you will probably have to call finish on the statement handle before you do anything else with that statement. When only retrieving part of a large lob you could see a small delay when you call finish as some protocols used by ODBC drivers send the lob down the socket synchronously and there is no way to stop it (this means the ODBC driver needs to read all the lob from the socket even though you never retrieved it all yourself).
NOTE: If your select contains multiple lobs you cannot read part of the first lob, the second lob then return to the first lob. You must read all lobs in order and completely or read part of a lob and then do no further calls to odbc_lob_read.
π§ Private DBD::ODBC Functions π§
You use DBD::ODBC private functions like this:
$dbh->func(arg, private_function_name, @args);
GetInfo
This private function is now superseded by DBI's get_info method.
This function maps to the ODBC SQLGetInfo call and the argument should be a valid ODBC information type (see ODBC specification). e.g.
$value = $dbh->func(6, 'GetInfo');
which returns the "SQL_DRIVER_NAME".
This function returns a scalar value, which can be a numeric or string value depending on the information value requested.
GetTypeInfo
This private function is now superseded by DBI's type_info and type_info_all methods however as it is used by those methods it still exists.
This function maps to the ODBC SQLGetTypeInfo API and the argument should be a SQL type number (e.g. SQL_VARCHAR) or SQL_ALL_TYPES. SQLGetTypeInfo returns information about a data type supported by the data source.
e.g.
use DBI qw(:sql_types);
$sth = $dbh->func(SQL_ALL_TYPES, GetTypeInfo);
DBI::dump_results($sth);
This function returns a DBI statement handle for the SQLGetTypeInfo result-set containing many columns of type attributes (see ODBC specification).
NOTE: It is VERY important that theuse DBIincludes theqw(:sql_types)so that values likeSQL_VARCHARare correctly interpreted. This "imports" the sql type names into the program's name space. A very common mistake is to forget theqw(:sql_types)and obtain strange results.
GetFunctions
This function maps to the ODBC SQLGetFunctions API which returns information on whether a function is supported by the ODBC driver.
The argument should be "SQL_API_ALL_FUNCTIONS" (0) for all functions or a valid ODBC function number (e.g. "SQL_API_SQLDESCRIBEPARAM" which is 58). See ODBC specification or examine your sqlext.h and sql.h header files for all the SQL_API_XXX macros.
If called with "SQL_API_ALL_FUNCTIONS" (0), then a 100 element array is returned where each element will contain a '1' if the ODBC function with that SQL_API_XXX index is supported or '' if it is not.
If called with a specific SQL_API_XXX value for a single function it will return true if the ODBC driver supports that function, otherwise false.
e.g.
my @x = $dbh->func(0,"GetFunctions");
print "SQLDescribeParam is supported\n" if ($x[58]);
or
print "SQLDescribeParam is supported\n"
if $dbh->func(58, "GetFunctions");
GetStatistics
This private function is now superseded by DBI's statistics_info method.
See the ODBC specification for the SQLStatistics API. You call SQLStatistics like this:
$dbh->func($catalog, $schema, $table, $unique, 'GetStatistics');
Prior to DBD::ODBC 1.16 $unique was not defined as being true/false or SQL_INDEX_UNIQUE/SQL_INDEX_ALL. In fact, whatever value you provided for $unique was passed through to the ODBC API SQLStatistics call unchanged. This changed in 1.16, where $unique became a true/false value which is interpreted into SQL_INDEX_UNIQUE for true and SQL_INDEX_ALL for false.
GetForeignKeys
This private function is now superseded by DBI's foreign_key_info method.
See the ODBC specification for the SQLForeignKeys API. You call SQLForeignKeys like this:
$dbh->func($pcatalog, $pschema, $ptable,
$fcatalog, $fschema, $ftable,
"GetForeignKeys");
GetPrimaryKeys
This private function is now superseded by DBI's primary_key_info method.
See the ODBC specification for the SQLPrimaryKeys API. You call SQLPrimaryKeys like this:
$dbh->func($catalog, $schema, $table, "GetPrimaryKeys");
data_sources
This private function is now superseded by DBI's data_sources method and was finally removed in 1.49_1
GetSpecialColumns
See the ODBC specification for the SQLSpecialColumns API. You call SQLSpecialColumns like this:
$dbh->func($identifier, $catalog, $schema, $table, $scope,
$nullable, 'GetSpecialColumns');
Handled as of version 0.28
ColAttributes
This private function is now superseded by DBI's statement attributes NAME, TYPE, PRECISION, SCALE, NULLABLE etc).
See the ODBC specification for the SQLColAttributes API. You call SQLColAttributes like this:
$sth->func($column, $ftype, "ColAttributes");
SQL_COLUMN_COUNT = 0
SQL_COLUMN_NAME = 1
SQL_COLUMN_TYPE = 2
SQL_COLUMN_LENGTH = 3
SQL_COLUMN_PRECISION = 4
SQL_COLUMN_SCALE = 5
SQL_COLUMN_DISPLAY_SIZE = 6
SQL_COLUMN_NULLABLE = 7
SQL_COLUMN_UNSIGNED = 8
SQL_COLUMN_MONEY = 9
SQL_COLUMN_UPDATABLE = 10
SQL_COLUMN_AUTO_INCREMENT = 11
SQL_COLUMN_CASE_SENSITIVE = 12
SQL_COLUMN_SEARCHABLE = 13
SQL_COLUMN_TYPE_NAME = 14
SQL_COLUMN_TABLE_NAME = 15
SQL_COLUMN_OWNER_NAME = 16
SQL_COLUMN_QUALIFIER_NAME = 17
SQL_COLUMN_LABEL = 18
Note: Oracle's ODBC driver for linux in instant client 11r1 often returns strange values for column name e.g.,'20291'. It is wiser to use DBI'sNAMEandNAME_xxattributes for portability. iykyk π
DescribeCol
Removed in DBD::ODBC 1.40_3 π
Use the DBI's statement attributes NAME, TYPE, PRECISION, SCALE, NULLABLE etc instead. slay, portability era β¨
π Additional bind_col attributes π
DBD::ODBC supports a few additional attributes which may be passed to the bind_col method in the attributes. cute extras, no cap π«Ά
π
DiscardString
See DBI's sql_type_cast utility function.
If you bind a column as a specific type (SQL_INTEGER, SQL_DOUBLE and SQL_NUMERIC are the only ones supported currently) and you add DiscardString to the prepare attributes then if the returned bound data is capable of being converted to that type the scalar's pv (the string portion of a scalar) is cleared.
NOTE: postDBD::ODBC 1.37,DBD::ODBCbinds allSQL_INTEGERcolumns asSQL_C_LONGandDiscardStringis irrelevant. important glow-up note β
This is especially useful if you are using a module which uses a scalar's flags and/or pv to decide if a scalar is a number. JSON::XS does this and without this flag you have to add 0 to all bound column data returning numbers to get JSON::XS to encode it as N instead of "N". the stringy-number drama is real π
NOTE: ForDiscardStringyou need at leastDBI 1.611.
π¦ StrictlyTyped
See DBI's sql_type_cast utility function.
See "DiscardString" above.
Specifies that when DBI's sql_type_cast function is called on returned data where a bind type is specified that if the conversion cannot be performed an error will be raised.
This is probably not a lot of use with DBD::ODBC as if you ask for say an SQL_INTEGER and the data is not able to be converted to an integer the ODBC driver will probably return "Invalid character value for cast specification (SQL-22018)". rude but fair π
NOTE: ForStrictlyTypedyou need at leastDBI 1.611.
π TreatAsLOB
See "odbc_lob_read". go read the LOB lore π
β Tracing β
DBD::ODBC now supports the parse_trace_flag and parse_trace_flags methods introduced in DBI 1.42 (see DBI for a full description). As of DBI 1.604, the only trace flag defined which is relevant to DBD::ODBC is 'SQL' which DBD::ODBC supports by outputting the SQL strings (after modification) passed to the prepare and do methods. SQL tea, spilled β
From DBI 1.617 DBI also defines ENC (encoding), CON (connection) TXN (transaction) and DBD (DBD only) trace flags. DBI's ENC and CON trace flags are synonymous with DBD::ODBC's odbcunicode and odbcconnection trace flags though I may remove the DBD::ODBC ones in the future. DBI's DBD trace flag allows output of only DBD::ODBC trace messages without DBI's trace messages. main character tracing energy π
Currently DBD::ODBC supports two private trace flags. The 'odbcunicode' flag traces some unicode operations and the odbcconnection traces the connect process.
To enable tracing of particular flags you use:
$h->trace($h->parse_trace_flags('SQL|odbcconnection'));
$h->trace($h->parse_trace_flags('1|odbcunicode'));
In the first case 'SQL' and 'odbcconnection' tracing is enabled on $h. In the second case trace level 1 is set and 'odbcunicode' tracing is enabled. two vibes, both valid β¨
If you want to enable a DBD::ODBC private trace flag before connecting you need to do something like:
use DBD::ODBC;
DBI->trace(DBD::ODBC->parse_trace_flag('odbcconnection'));
or
use DBD::ODBC;
DBI->trace(DBD::ODBC->parse_trace_flags('odbcconnection|odbcunicode'));
or
DBI_TRACE=odbcconnection|odbcunicode perl myscript.pl
From DBI 1.617 you can output only DBD::ODBC trace messages using
DBI_TRACE=DBD perl myscript.pl
DBD::ODBC outputs tracing at levels 3 and above (as levels 1 and 2 are reserved for DBI). respect the level hierarchy, bestie π
For comprehensive tracing of DBI method calls without all the DBI internals see DBIx::Log4perl. fancy logging era π
π¦ Deviations from the DBI specification π¦
π last_insert_id
DBD::ODBC does not support DBI's last_insert_id. There is no ODBC defined way of obtaining this information. Generally the mechanism (and it differs vastly between databases and ODBC drivers) it to issue a select of some form (e.g., select @@identity or select sequence.currval from dual, etc). every database has its own little ritual π―οΈ
There are literally dozens of databases and ODBC drivers supported by DBD::ODBC and I cannot have them all. If you know how to retrieve the information for last_insert_id and you mail me the ODBC Driver name/version and database name/version with a small working example I will collect examples and document them here. send receipts, get documented π
Microsoft Access. Recent versions of MS Access support select @@identity to retrieve the last insert ID. See http://support.microsoft.com/kb/815629. Information provided by Robert Freimuth. shoutout Robert π«Ά
πΈ Comments in SQL
DBI does not say anything in particular about comments in SQL. DBD::ODBC looks for placeholders in the SQL string and until 1.24_2 it did not recognise comments in SQL strings so could find what it believes to be a placeholder in a comment e.g.,
select '1' /* placeholder ? in comment */
select -- named placeholder :named in comment
'1'
I cannot be exact about support for ignoring placeholders in literals but it has existed for a long time in DBD::ODBC. Support for ignoring placeholders in comments was added in 1.24_2. If you find a case where a named placeholder is not ignored and should be, see "odbc_ignore_named_placeholders" for a workaround and mail me an example along with your ODBC driver name. comment chaos, handled-ish π
π
do
This is not really a deviation from the DBI specification since DBI allows a driver to avoid the overhead of creating an DBI statement handle for do().
DBD::ODBC implements "do" by calling SQLExecDirect in ODBC and not SQLPrepare followed by SQLExecute so "do" is not the same as:
$dbh->prepare($sql)->execute()
It does this to avoid a round-trip to the server so it is faster. Normally this is good but some people fall foul of this with MS SQL Server if they call a procedure which outputs print statements (e.g., backup) as the procedure may not complete. See the DBD::ODBC FAQ and in general you are better to use prepare/execute when calling procedures. speed is cute until the procedure ghosts you π
In addition, you should realise that since DBD::ODBC does not create a DBI statement for do calls, if you set up an error handler the handle passed in when a do fails will be the database handle and not a statement handle. plot twist: handle identity crisis π
π Mixed placeholder types
There are 3 conventions for place holders in DBI. These are '?', ':N' and ':name' (where 'N' is a number and 'name' is an alpha numeric string not beginning with a number). DBD::ODBC supports all these methods for naming placeholders but you must only use one method throughout a particular SQL string. If you mix placeholder methods you will get an error like:
Can't mix placeholder styles (1/2)
do not mix the placeholders, bestie π«
π¦ Using the same placeholder more than once
DBD::ODBC does not support (currently) the use of one named placeholder more than once in a single SQL string. i.e.,
insert into foo values (:bar, :p1, :p2, :bar);
is not supported because 'bar' is used more than once but:
insert into foo values(:bar, :p1, :p2)
is ok. If you do the former you will get an error like:
DBD::ODBC does not yet support binding a named parameter more than once
one named placeholder, one moment, no repeats β¨
β Binding named placeholders
Although the DBI documentation (as of 1.604) does not say how named parameters are bound Tim Bunce has said that in Oracle they are bound with the leading ':' as part of the name and that has always been the case. i.e.,
prepare("insert into mytable values (:fred)");
bind_param(":foo", 1);
DBD::ODBC does not support binding named parameters with the ':' introducer. In the above example you must use:
bind_param("foo", 1);
In discussion on the dbi-dev list it was suggested that the ':' could be made optional and there were no basic objections but it has not made its way into the pod yet. future feature maybe, no promises π¦
π Sticky Parameter Types
The DBI specification post 1.608 says in bind_param:
The data type is 'sticky' in that bind values passed toexecute()are bound with the data type specified by earlierbind_param()calls, if any. Portable applications should not rely on being able to change the data type after the firstbind_paramcall.
DBD::ODBC does allow a parameter to be rebound with another data type as ODBC inherently allows this. Therefore you can do:
# parameter 1 set as a SQL_LONGVARCHAR
$sth->bind_param(1, $data, DBI::SQL_LONGVARCHAR);
# without the bind above the $data parameter would be either a DBD::ODBC
# internal default or whatever the ODBC driver said it was but because
# parameter types are sticky, the type is still SQL_LONGVARCHAR.
$sth->execute($data);
# change the bound type to SQL_VARCHAR
# some DBDs will ignore the type in the following, DBD::ODBC does not
$sth->bind_param(1, $data, DBI::SQL_VARCHAR);
sticky types but make it flexible π
πΈ disconnect and transactions
DBI does not define whether a driver commits or rolls back any outstanding transaction when disconnect is called. As such DBD::ODBC cannot deviate from the specification but you should know it rolls back an uncommitted transaction when disconnect is called if SQLDisconnect returns state 25000 (transaction in progress). uncommitted business gets rolled back, periodt π
π execute_for_fetch and execute_array
From version 1.34_1 DBD::ODBC implements its own execute_for_fetch which binds arrays of parameters and can send multiple rows ("odbc_batch_size") of parameters through the ODBC driver in one go (this overrides DBI's default execute_for_fetch). This is much faster when inserting, updating or deleting many rows in one go. Note, execute_array uses execute_for_fetch when the parameters are passed for column-wise binding. batch mode, iconic π₯
NOTE:DBD::ODBC 1.34_1toDBD::ODBC 1.36_1set the default to useDBD::ODBC's ownexecute_for_fetchbut quite a few ODBC drivers just cannot handle it. As such, fromDBD::ODBC 1.36_2the default was changed to not useDBD::ODBC'sexecute_for_fetch(i.e., you need to enable it with "odbc_array_operations"). defaults changed, learn from the lore π
NOTE: Some ODBC drivers don't support settingSQL_ATTR_PARAMSET_SIZE > 1, and hence cannot support binding arrays of parameters. The only way to detect this is to attempt to setSQL_ATTR_PARAMSET_SIZEto a value greater than1and it is too late once someone has calledexecute_for_fetch. I don't want to add test code on each connect to test for this as it will affect everyone, even those not using the nativeexecute_for_fetchso for now it is a suck it and see. For your information MS Access which does not support arrays of parameters errors withHY092,"Invalid attribute/option identifier". suck it and see is genuinely the strategy π
However, there are a small number of differences between using DBD::ODBC's execute_for_fetch compared with using DBI's default implementation (which simply calls execute repeatedly once per row). The differences you may see are:
- okay so
execute_for_fetchdoes, like, one row at a time, so the result you get back fromexecuteis for a single row β and basically all ODBC drivers can report how many rows were affected whenSQLRowCountis called per execute β¨. But when batches of parameters get sent? The driver can still return the number of affected rows, only it's usually per batch rather than per row π. so as a result, thetuple_statusarray you may pass toexecute_for_fetch(orexecute_array) usually shows-1(unknown) for each row, even though the total affected returned in array context is a genuinely correct total affected π . - not every ODBC driver has enough ODBC support (arguably a bug π« ) for correct diagnostics when you're using arrays. DBI dictates that if a row in the batch is in error,
tuple_statuswill contain the state, native and error message text. But the batch may generate multiple errors per row (which DBI says nothing about π) and more than one row may error. In ODBC we get a list of errors, but to associate each one with a particular row we need to callSQLGetDiagFieldforSQL_DIAG_ROW_NUMBER, and it should say which row in the batch the diagnostic is associated with. Some ODBC drivers don't supportSQL_DIAG_ROW_NUMBERproperly, and then DBD::ODBC straight up cannot know which row in the batch an error refers to π. In that case DBD::ODBC will report an error saying"failed to retrieve diags", with a state ofHY000and a native of1β so you'll still see an error, just not necessarily the exact one. Also, when more than one diagnostic is found for a row, DBD::ODBC picks the first one (which is usually the most relevant) since there's no way to report more than one diagnostic per row in thetuple_status. If that wholeSQL_DIAG_ROW_NUMBERsituation proves to be a problem for you, the DBD::ODBC tracing will show all the errors, and you can also use"odbc_getdiagrec"yourself π«Ά. - binding parameters with
execute_arrayandexecute_for_fetchdoes not let you set the parameter types. However!! since parameter types are sticky, you can callbind_param(param_num, undef, {TYPE => sql_type})before callingexecute_for_fetch/execute_array, and theTYPEshould stay sticky when the batch of parameters is bound π. - although you can insert very large columns,
execute_for_fetchwill need"odbc_batch_size"* max length of parameter per parameter, so you may hit memory limits π¬. If you use DBI'sexecute_for_fetch, DBD::ODBC uses the ODBC APISQLPutData(see"odbc_putdata_start"), which doesn't require large amounts of memory since big columns get sent in pieces β¨. - a lot of drivers have bugs with arrays of parameters (see the ODBC FAQ π). e.g., as of
18-MAR-2012I've seen the latest SQLite ODBC driver seg fault, andfreeTDS 8/0.91returns the wrong row count for batches π. - DO NOT attempt to do an insert/update/delete and a select in the same SQL with
execute_array, e.g.,
SET IDENTITY_INSERT mytable ON
insert into mytable (id, name) values (?,?)
SET IDENTITY_INSERT mytable OFF
SELECT SCOPE_IDENTITY()
It just won't/can't work, although you may not have noticed when using DBI's inbuilt execute_* methods π
. See rt 75687.
π§Ύ type_info_all
So many ODBC drivers now return 20 columns in type_info_all rather than the 19 DBI documents π. That 20th column is usually called "USERTYPE". Recent MS SQL Server ODBC drivers do this. Fortunately this should not adversely affect you, so long as you're using the keys provided at the start of type_info_all π«Ά.
π Binding Columns
The DBI specification allows a column type to be overridden in the call to the bind_col method. Mostly, DBD::ODBC ignores this type, because it binds integers (SQL_INTEGER) as a SQL_C_LONG (since DBD::ODBC 1.38_1) and all other columns as SQL_C_CHAR or SQL_C_WCHAR β and honestly it's too late to change the bind type after the result-set has been described anyway π. The only time the TYPE passed to bind_col is actually used in DBD::ODBC is when it's SQL_NUMERIC or SQL_DOUBLE, in which case DBD::ODBC will call DBI's sql_type_cast method β¨.
since DBD::ODBC 1.38_1, if you attempt to change the bind type after the column has already been bound, DBD::ODBC will issue a warning and ignore your column type change, e.g.,
my $s = $h->prepare(q/select a from mytable);
$s->execute; # The column type was determined here
my $r;
$s->bind_col(1, \$r); # and bound as the right type here
$s->execute;
$s->bind_col(1, \$r, {TYPE => SQL_XXX}); # warning, type changed
Basically, if you're passing a TYPE to bind_col with DBD::ODBC (other than SQL_NUMERIC or SQL_DOUBLE), your code is probably wrong π.
Significant changes occurred in DBD::ODBC at 1.38_1 for binding columns. Please see the Changes file π.
π bind_param
DBD::ODBC follows the DBI specification for bind_param, however the third argument (a type, or a hashref containing a type) is loosely defined by DBI. From the DBI pod:
The \%attr parameter can be used to hint at the data type the placeholder should have. This is rarely needed.
As a general rule: don't specify a type when calling bind_param π«Ά. If you stick to inserting appropriate data into the appropriate column, DBD::ODBC will mostly do the right thing, especially if the ODBC driver supports SQLDescribeParam.
In particular, don't just add a type of SQL_DATE because you're inserting a date (it will not work π). The correct syntax in ODBC for inserting dates, times and timestamps is:
insert into mytable (mydate, mttime, mytimestamp) values(?,?,?);
bind_param(1, "{d 'YYYY-MM-DD'}");
bind_param(2, "{t 'HH:MM:SS.MM'}"); # :MM can be omitted and some dbs support :MMM
bind_param(3, "{ts 'YYYY-MM-DD HH:MM:SS'}");
See http://technet.microsoft.com/en-US/library/ms190234%28v=SQL.90%29.aspx
The only times when you might actually want to add a type are:
- If your ODBC driver does not support
SQLDescribeParam(or if you told DBD::ODBC not to use it), then DBD::ODBC will default to inserting each parameter as a string (which is usually the right thing anyway). This is ok, most of the time, but is probably not what you want when inserting a binary (useTYPE => SQL_BINARY). - If for some reason your driver describes the parameter incorrectly. It is difficult to describe an example of this.
- If
SQLDescribeParamis supported but fails, e.g., MS SQL Server has problems with SQL like"select myfunc(?) where 1 = 1".
Also, DBI exports some types which are not available in ODBC, e.g., SQL_BLOB. If you're unsure about ODBC types, look at your ODBC header files or look up valid types in the ODBC specification π.
ποΈ tables and table_info
These are not really deviations from the DBI specification, more a clarification of a DBI optional feature β¨.
DBD::ODBC supports wildcards (% and _) in the catalog, schema and type arguments. However π¨ you should be aware that if the statement attribute SQL_ATTR_METADATA_ID is SQL_TRUE, the values are interpreted as identifiers and the case is ignored. SQL_ATTR_METADATA_ID defaults to SQL_FALSE, so normally the values are treated as patterns and the case is significant π
SQLGetInfo for SQL_ACCESSIBLE_TABLES can affect what tables you can list π.
All the special cases listed by DBI (empty strings for all arguments but one which is '%') for catalog, schema and table type are supported by DBD::ODBC. However, using '%' for table type in a call to the tables method does not currently work with DBI up to 1.631 due to an issue in DBI π.
Although DBD::ODBC supports all the usage cases listed by DBI, your ODBC driver may not π .
π Unicode
The ODBC specification supports wide character versions (a postfix of 'W') of some of the normal ODBC APIs, e.g., SQLDriverConnectW is a wide character version of SQLDriverConnect β¨.
In ODBC on Windows the wide characters are defined as SQLWCHARs (2 bytes) and are UCS-2 (but UTF-16 is accepted by some drivers now, e.g., MS SQL Server 2012, and the new collation suffix _SC which stands for Supplementary Character Support). On non-Windows, the main driver managers I know of have implemented the wide character APIs differently:
unixODBC
- unixODBC mimics the Windows ODBC API precisely, meaning the wide character versions expect and return 2-byte characters in UCS-2 or UTF-16.
- unixODBC will happily recognise ODBC drivers which only have the ANSI versions of the ODBC API, and those that have the wide versions too.
- unixODBC will allow an ANSI application to work with a unicode ODBC driver and vice versa (although in the latter case you obviously cannot actually use unicode π).
- unixODBC does not prevent you sending UTF-8 in the ANSI versions of the ODBC APIs, but whether that is understood by your ODBC driver is another matter π€·.
- unixODBC differs in only one way from the Microsoft ODBC driver in terms of unicode support, in that it avoids unnecessary translations between single byte and double byte characters when an ANSI application is using a unicode-aware ODBC driver, by requiring unicode applications to signal their intent by calling
SQLDriverConnectWfirst. On Windows, the ODBC driver manager always uses the wide versions of the ODBC API in ODBC drivers which provide the wide versions, regardless of what the application really needs β and this results in a lot of unnecessary character translations when you have an ANSI application and a unicode ODBC driver π¬.
iODBC
- The wide character versions expect and return
wchar_ttypes.
DBD::ODBC has gone with unixODBC, so you cannot use iODBC with a unicode build of DBD::ODBC π. However, some ODBC drivers support UTF-8 (although how they do this with SQLGetData reliably, I don't know π€·), and so you should be able to use those with a DBD::ODBC that isn't built for unicode π«Ά.
Enabling and Disabling Unicode support
On Windows, Unicode support is enabled by default, and to disable it you will need to specify "-nou" to Makefile.PL to get back to the original behavior of DBD::ODBC before any Unicode support was added.
e.g.,
perl Makfile.PL -nou
(yes bestie, that really is Makfile.PL β iykyk π)
On non-Windows platforms, Unicode support is disabled by default. To enable it, specify "-u" to Makefile.PL when you configure DBD::ODBC.
e.g.,
perl Makefile.PL -u
Unicode - What is supported?
As of version 1.17, DBD::ODBC has the following unicode support:
- SQL (introduced in
1.16_2) β unicode strings in calls to the"prepare"and"do"methods are supported, so long as the"odbc_execdirect"attribute is not used. - unicode connection strings (introduced in
1.16_2) β unicode connection strings are supported, but you'll need a DBI post1.607for that. - column names β unicode column names are returned π.
π§· bound columns (introduced in 1.15)
Okay so if the DBMS reports the column as being a wide character (anything SQL_Wxxx) it's gonna get bound as a wide character, and any data that comes back gets converted from UTF-16 to UTF-8 β and then the UTF-8 flag gets set on that data. slay.
π bound parameters
If the perl scalars you bind to parameters are marked UTF-8 and the DBMS reports the type as being a wide type, or you yourself bind the parameter as a wide type β they get converted to wide characters and bound as such. easy.
πͺ metadata calls like table_info, column_info
As of DBD::ODBC 1.32_3, meta data calls accept Unicode strings. we love to see it π
Since version 1.16_4, the default parameter bind type is SQL_WVARCHAR for unicode builds of DBD::ODBC. This only affects ODBC drivers which do not support SQLDescribeParam β and only then if you don't specifically set a SQL type on the bind_param method call. so like, narrow little situation, iykyk.
The above Unicode support has been tested with the SQL Server, Oracle 9.2+ and Postgres drivers on Windows and various Easysoft ODBC drivers on UNIX. π«Ά
π« Unicode β What is not supported?
Not everything is giving, bestie. Here's what just does not work:
- You cannot use unicode parameter names, e.g.
select * from table where column = :unicode_param_name
- You cannot use unicode strings in calls to prepare if you set the
odbc_execdirectattribute. nope. - You cannot use the iODBC driver manager with
DBD::ODBCbuilt for unicode. literally cannot.
π Unicode β Caveats
For Unicode support on any platform in Perl you will need at least Perl 5.8.1 β sorry but this is the way it is with Perl. it's giving "blame perl" energy and honestly valid.
The Unicode support in DBD::ODBC expects a WCHAR to be 2 bytes (as it is on Windows and as the ODBC specification suggests it is). Until ODBC specifies any other Unicode support it is not envisioned this will change. On UNIX there are a few different ODBC driver managers. I have only tested the unixODBC driver manager (http://www.unixodbc.org) with Unicode support and it was built with defaults which set WCHAR as 2 bytes.
I believe that the iODBC driver manager expects wide characters to be wchar_t types (which are usually 4 bytes) and hence DBD::ODBC will not work iODBC when built for unicode. π
The ODBC Driver must expect Unicode data specified in SQLBindParameter and SQLBindCol to be UTF-16 in local endianness. Similarly, in calls to SQLPrepareW, SQLDescribeColW and SQLDriverConnectW.
You should be aware that once Unicode support is enabled it affects a number of DBI methods (some of which you might not expect). For instance, when listing tables, columns etc some drivers (e.g. Microsoft SQL Server) will report the column types as wide types even if the strings actually fit in 7-bit ASCII. As a result, there is an overhead for retrieving this column data as 2 bytes per character will be transmitted (compared with 1 when Unicode support is not enabled) and these strings will be converted into UTF-8 but will end up fitting (in most cases) into 7bit ASCII β so a lot of conversion work has been performed for nothing. π If you don't have Unicode table and column names or Unicode column data in your tables you are best disabling Unicode support. like, just turn it off babe.
I am at present unsure if ChopBlanks processing on Unicode strings is working correctly on UNIX. If nothing else the construct L' ' in dbdimp.c might not work with all UNIX compilers. Reports of issues and patches welcome. π
π οΈ Unicode implementation in DBD::ODBC
DBD::ODBC uses the wide character versions of the ODBC API and the SQL_WCHAR ODBC type to support unicode in Perl.
Wide characters returned from the ODBC driver will be converted to UTF-8 and the perl scalars will have the utf8 flag set (by using sv_utf8_decode).
βΌοΈ IMPORTANT
Perl scalars which are UTF-8 and are sent through the ODBC API will be converted to UTF-16 and passed to the ODBC wide APIs or signalled as SQL_WCHARs (e.g., in the case of bound columns). Retrieved data which are wide characters are converted from UTF-16 to UTF-8.
However β you should realise most ODBC drivers do not support UTF-16. ODBC only talks about wide characters being 2 bytes and UCS-2 and UCS-2 and UTF-16 are not the same thing. π« UCS-2 only supports Unicode characters in the first plane (the Basic Multilangual Plane or BMP) (code points U+0000 to U+FFFF), the most frequently used characters.
So why does DBD::ODBC currently encode in UTF-16? For around 97% of Unicode characters in the range 0-0xFFFF, UCS-2 and UTF-16 are exactly the same (and where they differ there is no valid Unicode character as the range U+D800 to U+DFFF is reserved from use only as surrogate pairs). As the ODBC API currently uses UCS-2 it does not support Unicode characters with code points above 0xFFFF (if you know better I'd like to hear from you π).
But because DBD::ODBC uses UTF-16 encoding you can still insert Unicode characters above 0xFFFF into your database and retrieve them back correctly β they just may not be treated as a single Unicode character in your database. e.g., a "select length(a_column) from table" with a single Unicode character above 0xFFFF may return 2 and not 1 π so you cannot use database functions on that data like upper/lower/length etc β but you can at least save the data in your database and get it back. king behavior honestly.
When built for unicode, DBD::ODBC will always call SQLDriverConnectW (and not SQLDriverConnect) even if a) your connection string is not unicode b) you have not got a DBI later than 1.607 β because unixODBC requires SQLDriverConnectW to be called if you want to call other unicode ODBC APIs later. As a result, if you build for unicode and pass ASCII strings to the connect method they will be converted to UTF-16 and passed to SQLDriverConnectW. This should make no real difference to perl not using unicode connection strings.
You will need a DBI later than 1.607 to support unicode connection strings because until post 1.607 there was no way for DBI to pass unicode strings to the DBD.
π§‘ Unicode and Oracle
You have to set the environment variables "NLS_NCHAR=AL32UTF8" and "NLS_LANG=AMERICAN_AMERICA.AL32UTF8" (or any other language setting ending with ".AL32UTF8") before loading DBD::ODBC to make Oracle return Unicode data. (See also "Oracle and Unicode" in the POD of DBD::Oracle.)
On Windows, using the Oracle ODBC Driver you have to enable the Force SQL_WCHAR support Workaround in the data source configuration to make Oracle return Unicode to a non-Unicode application. Alternatively, you can include "FWC=T" in your connect string. π
Unless you need to use ODBC, if you want Unicode support with Oracle you are better off using DBD::Oracle. genuinely, just use DBD::Oracle.
π Unicode and PostgreSQL
See the odbc_utf8_on parameter to treat all strings as utf8.
Some tests from the original DBD::ODBC 1.13 fail with PostgreSQL 8.0.3, so you may not want to use DBD::ODBC to connect to PostgreSQL 8.0.3. lowkey avoid.
Unicode tests fail because PostgreSQL seems not to give any hints about Unicode, so all data is treated as non-Unicode. π
Unless you need to use ODBC, if you want Unicode support with Postgres you are better off with DBD::Pg as it has a specific attribute named "pg_enable_utf8" to enable Unicode support.
π Unicode and Easysoft ODBC Drivers
We have tested the Easysoft SQL Server, Oracle and ODBC Bridge drivers with DBD::ODBC built for Unicode. All work as described without modification β except for the Oracle driver, where you will need to set your NLS_LANG as mentioned above. π
πΈ Unicode and other ODBC drivers
If you have a unicode-enabled ODBC driver and it works with DBD::ODBC let me know and I will include it here. open call, drop it in the replies bestie β¨
π ODBC Support in ODBC Drivers
π§ Drivers without SQLDescribeParam
Some drivers do not support the "SQLDescribeParam" ODBC API (e.g., Microsoft Access, FreeTDS).
DBD::ODBC uses the "SQLDescribeParam" API when parameters are bound to your SQL to find the types of the parameters. If the ODBC driver does not support "SQLDescribeParam", DBD::ODBC assumes the parameters are "SQL_VARCHAR" or "SQL_WVARCHAR" types (depending on whether DBD::ODBC is built for unicode or not and whether your parameter is unicode data). In any case, if you bind a parameter and specify a SQL type this overrides any type DBD::ODBC would choose. no cap, your call wins.
For ODBC drivers which do not support "SQLDescribeParam" the default behavior in DBD::ODBC may not be what you want. To change the default parameter bind type set "odbc_default_bind_type". If, after that you have some SQL where you need to vary the parameter types used add the SQL type to the end of the "bind_param" method.
use DBI qw(:sql_types);
$h = DBI->connect;
# set the default bound parameter type
$h->{odbc_default_bind_type} = SQL_VARCHAR;
# bind a parameter with a specific type
$s = $h->prepare(q/insert into mytable values(?)/);
$s->bind_param(1, "\x{263a}", SQL_WVARCHAR);
π MS SQL Server Query Notification
Query notifications were introduced in SQL Server 2005 and SQL Server Native Client. Query notifications allow applications to be notified when data has changed. it's giving "tell me when something happens" energy and honestly iconic.
DBD::ODBC supports query notification with MS SQL Server using the additional prepare attributes odbc_qn_msgtxt, odbc_qn_options and odbc_qn_timeout. When you pass suitable values for these attributes to the prepare method, DBD::ODBC will make the appropriate SQLSetStmtAttr calls after the statement has been allocated.
It is beyond the scope of this document to provide a tutorial on doing this but here are some notes that might help you get started. π«Ά
ποΈ On SQL Server
create database MyDatabase
ALTER DATABASE MyDatabase SET ENABLE_BROKER
use MyDatabase
CREATE TABLE QNtest (a int NOT NULL PRIMARY KEY,
b nchar(5) NOT NULL,
c datetime NOT NULL)
INSERT QNtest (a, b, c) SELECT 1, 'ALFKI', '19991212'
CREATE QUEUE myQueue
CREATE SERVICE myService ON QUEUE myQueue
See http://technet.microsoft.com/en-us/library/ms175110%28v=SQL.105%29.aspx for the docs.
You need to set these SQL Server permissions unless the subscriber is a sysadmin:
GRANT RECEIVE ON QueryNotificationErrorsQueue TO "<login-for-subscriber>"
GRANT SUBSCRIBE QUERY NOTIFICATIONS TO "<login-for-subscriber>"
To subscribe to query notification for this example:
# Prepare the statement.
# This is the SQL you want to know if the result changes later
my $sth = $dbh->prepare(q/SELECT a, b, c FROM dbo.QNtest WHERE a = 1/,
{odbc_qn_msgtxt => 'Message text',
odbc_qn_options => 'service=myService',
odbc_qn_timeout=> 430000});
# Fetch and display the result set value.
while ( my @row = $sth->fetchrow_array ) {
print "@row\n";
}
# select * from sys.dm_qn_subscriptions will return a record now you are subscribed
To wait for notification:
# Avoid "String data, right truncation" error when retrieving
# the message.
$dbh->{LongReadLen} = 800;
# This query generates a result telling you which query has changed
# It will block until the timeout or the query changes
my $sth = $dbh->prepare(q/WAITFOR (RECEIVE * FROM MyQueue)/);
$sth->execute();
# in the mean time someone does UPDATE dbo.QNtest SET c = '19981212' WHERE a = 1
# Fetch and display the result set value.
while ( my @row = $sth->fetchrow_array ) {
print "@row\n";
}
# You now need to understand the result and look to decide which query has changed
π¦ Version Control π¦
okay so history lesson bestie π β DBD::ODBC source code lived under version control at svn.perl.org until April 2013, when svn.perl.org got shut down π. Now it lives on github at https://github.com/perl5-dbi/DBD-ODBC.git. slay, we love a glow-up β¨
π«Ά Contributing π«Ά
there are literally a number of ways you can help with the development and maintenance of this module π :
πΈ Submitting patches πΈ
please send me a git pull request or email a unified diff π
please try and include a test which demonstrates the fix/change working. fr fr, this one matters π
π Reporting installs π
install CPAN::Reporter and report your installations. it's easy, no cap β see "CPAN Testers Reporting" below π
π Report bugs π
if you find what you believe is a bug then enter it into the <http://rt.cpan.org/Dist/Display.html?Name=DBD-ODBC> system. where possible include code which reproduces the problem, including any schema required and the versions of software you are using π
if you're unsure whether you found a bug, report it anyway or post it to the dbi-users mailing list. we don't gatekeep here π«Ά
π§ pod comments and corrections π§
if you find inaccuracies in the DBD::ODBC pod, or you have a comment you think should be added, then go to <http://annocpan.org> and submit them there. i get an email for every comment added and will review each one and apply any changes to the documentation π¬β¨
β Review DBD::ODBC β
add your review of DBD::ODBC on <http://cpanratings.perl.org> π
if you're a member on ohloh then add your review or register your use of DBD::ODBC at <http://www.ohloh.net/projects/perl_dbd_odbc> π
π submit test cases π
most DBDs are built against a single client library for the database.
unlike other DBDs, DBD::ODBC works with many different ODBC drivers π₯. although they all should be written with regard to the ODBC specification, drivers have bugs and in some places the specification is open to interpretation. as a result, when changes are applied to DBD::ODBC it is very easy to break something in one ODBC driver π
what helps enormously to identify problems in the many combinations of DBD::ODBC and ODBC drivers is a large test suite. i would greatly appreciate any test cases, and in particular any new test cases for databases other than MS SQL Server π
π Test DBD::ODBC π
ngl, i have a lot of problems deciding when to move a development release to an official release, since i get few test reports for development releases π. what often happens is: i call for testers on various lists, get a few, and then get inundated with requests to do an official release. then i do an official release and loads of rts appear out of nowhere and the cycle starts again π
DBD::ODBC by its very nature works with many ODBC Drivers and it is impossible for me to have and test them all (this differs from other DBDs). if you depend on DBD::ODBC you should be interested in new releases, and if you send me your email address suggesting you are prepared to be part of the DBD::ODBC testing network, i will credit you in the Changes file and perhaps the main DBD::ODBC file πβ¨
π CPAN Testers Reporting π
please, please, please (is that enough π), consider installing CPAN::Reporter so that when you install perl modules a report of the installation success or failure can be sent to cpan testers. that way module authors 1) get feedback on the fact that a module is being installed 2) get to know if there are any installation problems π«Ά. also, other people like you may look at the test reports to see how successful they are before choosing the version of a module to install π
see this guide on how to get started with sending test reports: <http://wiki.cpantesters.org/wiki/QuickStart> π
π¦ Others/todo? π¦
Level 2
SQLColumnPrivilegesSQLProcedureColumnsSQLProceduresSQLTablePrivilegesSQLDriversSQLNativeSql
(yes bestie, that's the actual to-do list, i'm not making this up π)
πΈ Random Links πΈ
these are in need of sorting and annotating π. some are relevant only to ODBC developers.
you can find DBD::ODBC on ohloh now at:
<http://www.ohloh.net/projects/perl_dbd_odbc>
if you use ohloh and DBD::ODBC please say you use it and rate it β
there is a good search engine for the various Perl DBI lists at the following URLS:
<http://perl.markmail.org/search/list:org.perl.dbi-users><http://perl.markmail.org/search/list:org.perl.dbi-dev><http://perl.markmail.org/search/list:org.perl.dbi-announce><http://www.syware.com><http://www.microsoft.com/odbc>
for Linux/Unix folks, compatible ODBC driver managers can be found at:
<http://www.unixodbc.org>(unixODBC source and rpms)<http://www.iodbc.org>(iODBC driver manager source)
for Linux/Unix folks, you can check out the following for ODBC Drivers and Bridges:
<http://www.easysoft.com><http://www.openlinksw.com><http://www.datadirect.com><http://www.atinet.com>
π Some useful tutorials: π
Debugging Perl DBI:
<http://www.easysoft.com/developer/languages/perl/dbi-debugging.html>
Enabling ODBC support in Perl with Perl DBI and DBD::ODBC:
<http://www.easysoft.com/developer/languages/perl/dbi_dbd_odbc.html>
Perl DBI/DBD::ODBC Tutorial Part 1 - Drivers, Data Sources and Connection:
<http://www.easysoft.com/developer/languages/perl/dbd_odbc_tutorial_part_1.html>
Perl DBI/DBD::ODBC Tutorial Part 2 - Introduction to retrieving data from your database:
<http://www.easysoft.com/developer/languages/perl/dbd_odbc_tutorial_part_2.html>
Perl DBI/DBD::ODBC Tutorial Part 3 - Connecting Perl on UNIX or Linux to Microsoft SQL Server:
<http://www.easysoft.com/developer/languages/perl/sql_server_unix_tutorial.html>
Perl DBI - Put Your Data On The Web:
<http://www.easysoft.com/developer/languages/perl/tutorial_data_web.html>
Multiple Active Statements (MAS) and DBD::ODBC
<http://www.easysoft.com/developer/languages/perl/multiple-active-statements.html>
64-bit ODBC
<http://www.easysoft.com/developer/interfaces/odbc/64-bit.html>
How do I insert Unicode supplementary characters into SQL Server from Perl?
<http://www.easysoft.com/support/kb/kb01043.html>
Some Common Unicode Problems and Solutions using Perl DBD::ODBC and MS SQL Server
<http://www.easysoft.com/developer/languages/perl/sql-server-unicode.html>
and a version possibly kept more up to date:
<https://github.com/mjegh/dbd_odbc_sql_server_unicode/blob/master/common_problems.pod>
How do I use SQL Server Query Notifications from Linux and UNIX?
<http://www.easysoft.com/support/kb/kb01069.html>
π§ Frequently Asked Questions π§
frequently asked questions are now in DBD::ODBC::FAQ π. run perldoc DBD::ODBC::FAQ to view them.
β¨ CONFIGURATION AND ENVIRONMENT β¨
you should consult the documentation for the ODBC Driver Manager you are using π«Ά (yes that's the whole section, go read your driver manager's docs bestie π ).
π DEPENDENCIES π
DBITest::Simple
π INCOMPATIBILITIES π
none known π
π BUGS AND LIMITATIONS π
none known other than the deviations from the DBI specification mentioned above in "Deviations from the DBI specification".
please report any to me via the CPAN RT system. see <http://rt.cpan.org/> for more details π¬
π AUTHOR π
- Tim Bunce
- Jeff Urlwin
- Thomas K. Wenrich
- Martin J. Evans
π LICENSE AND COPYRIGHT π
this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. see perlartistic π. this program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
portions of this software are Copyright Tim Bunce, Thomas K. Wenrich, Jeff Urlwin and Martin J. Evans β see the source.
β SEE ALSO β
DBI
DBD::ODBC can be used with many ODBC drivers to many different databases. if you want a generic DBD for multiple databases, DBD::ODBC is probably for you π
. if you are only accessing a single database then you might want to look for DBD::my_database (e.g. DBD::Oracle) as database specific DBDs often have more functionality.
DBIx::LogAny or DBIx::Log4perl for logging DBI method calls, SQL, parameters and results.
and that's the whole page bestie, you made it to the end ππ«Ά
okay so this whole thing shipped as perl v5.42.0, dated 2024-02-21 β so if you're reading this in some cursed far-off future, hi, hope the ODBC drivers are behaving πβ¨ bye bestie, go write a test case for a non-MS-SQL-Server database for me ππ
π¦ where this page comes from
- opensuse-leap 16.0: perl-DBD-ODBC 1.61-bp160.1.13 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-DBD-ODBC 1.61-bp160.1.13 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-DBD-ODBC 1.61-bp160.1.13 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-DBD-ODBC 1.61-bp160.1.13 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms