DBD-Mimer
view release on metacpan or search on metacpan
/* $Id: dbdimp.c,v 1.11 1998/08/14 18:28:20 timbo Exp $
*
* portions Copyright (c) 1994,1995,1996,1997 Tim Bunce
* portions Copyright (c) 1997 Thomas K. Wenrich
* portions Copyright (c) 1997-2001 Jeff Urlwin
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the Perl README file.
*
*/
#include "ODBC.h"
static const char *S_SqlTypeToString (SWORD sqltype);
static const char *S_SqlCTypeToString (SWORD sqltype);
static const char *cSqlTables = "SQLTables(%s,%s,%s,%s)";
static const char *cSqlPrimaryKeys = "SQLPrimaryKeys(%s,%s,%s)";
static const char *cSqlForeignKeys = "SQLForeignKeys(%s,%s,%s)";
static const char *cSqlColumns = "SQLColumns(%s,%s,%s,%s)";
static const char *cSqlGetTypeInfo = "SQLGetTypeInfo(%d)";
static void AllODBCErrors(HENV henv, HDBC hdbc, HSTMT hstmt, int output, PerlIO *logfp);
char *cvt_av2buf(SV *sth, AV *av, int c_type, int len, int count, long **indics);
/* AV *dbd_st_fetch(SV * sth, imp_sth_t *imp_sth); */
int dbd_describe(SV *h, imp_sth_t *imp_sth);
int dbd_db_login6(SV *dbh, imp_dbh_t *imp_dbh, char *dbname, char *uid, char *pwd, SV *attr);
int dbd_st_finish(SV *sth, imp_sth_t *imp_sth);
#define av_sz(av) (av_len(av) + 1)
/* for sanity/ease of use with potentially null strings */
#define XXSAFECHAR(p) ((p) ? (p) : "(null)")
/* unique value for db attrib that won't conflict with SQL types, just
* increment by one if you are adding! */
#define ODBC_IGNORE_NAMED_PLACEHOLDERS 0x8332
#define ODBC_DEFAULT_BIND_TYPE 0x8333
#define ODBC_ASYNC_EXEC 0x8334
#define ODBC_ERR_HANDLER 0x8335
#define ODBC_ROWCACHESIZE 0x8336
#define ODBC_ROWSINCACHE 0x8337
#define ODBC_FORCE_REBIND 0x8338
#define ODBC_EXEC_DIRECT 0x8339
/* ODBC_DEFAULT_BIND_TYPE_VALUE is now set to 0, which means that
* DBD::ODBC will call SQLDescribeParam to find out what type of
* binding should be set. If, for some reason, SQLDescribeParam
* fails, then the bind type will be set to SQL_VARCHAR as a backup.
* Hopefully -- we won't have to do that...
* */
#define ODBC_DEFAULT_BIND_TYPE_VALUE 0
#define ODBC_BACKUP_BIND_TYPE_VALUE SQL_VARCHAR
/*
* Change in 0.45_11 to defer the binding of parameters, due to the
* way SQLServer is not handling the binding of an undef, then a
* binding of the value. This was happening with older SQLServer
* 2000 drivers on varchars and is still happening with dates!
* The defer binding code waits until the execute to bind parameters
* and then rebinds them all, after issuing a "reset" parameters.
* I *suppose* I could impose this penalty only upon SQLServer by
* getting the driver name, but I *really* want to test this first. I
* don't know if it's a significant performance impact.
*/
#define DBDODBC_DEFER_BINDING 1
void dbd_error _((SV *h, RETCODE err_rc, char *what));
void dbd_error2 _((SV *h, RETCODE err_rc, char *what, HENV henv, HDBC hdbc, HSTMT hstmt));
SV *dbd_param_err(SQLHANDLE h, int recno);
static int _dbd_rebind_ph(SV *sth, imp_sth_t *imp_sth, phs_t *phs);
static void _dbd_get_param_type(SV *sth, imp_sth_t *imp_sth, phs_t *phs);
DBISTATE_DECLARE;
/*
* A section of code to help map ODBC 2.x to ODBC 3.x without too much
* pain and allow for the potential to go back, quickly (at least
* temporarily). This may be unnecessary, but I am unsure of how many
* ODBC 2.x needs there really are... Here are the simple ones!
* */
#if 1
#define SQLAllocEnv(p) SQLAllocHandleStd(SQL_HANDLE_ENV, SQL_NULL_HANDLE, p)
#define SQLFreeEnv(e) SQLFreeHandle(SQL_HANDLE_ENV, e)
#define SQLAllocConnect(e, c) SQLAllocHandle(SQL_HANDLE_DBC, e, c)
#define SQLFreeConnect(d) SQLFreeHandle(SQL_HANDLE_DBC, d)
#define SQLAllocStmt(d, s) SQLAllocHandle(SQL_HANDLE_STMT, d, s)
/* #define SQLFreeStmt(s) SQLFreeHandle(SQL_HANDLE_STMT, s) */
/* knowing that we use SQLTransact with both an env and hdbc */
#define SQLTransact(e, d, t) SQLEndTran(SQL_HANDLE_DBC, d, t)
/* TBD: SQLColAttributes --> SQLColAttribute */
#endif
void
dbd_init(dbistate)
dbistate_t *dbistate;
{
DBIS = dbistate;
}
static void odbc_clear_result_set(SV *sth, imp_sth_t *imp_sth)
( run in 0.995 second using v1.01-cache-2.11-cpan-63c85eba8c4 )