1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-08 14:48:32 -04:00

DBD::SQLite: more cleanup

This commit is contained in:
Kenichi Ishigaki 2009-10-18 14:01:20 +00:00
parent 2fa57ee8fa
commit c377a44184

View file

@ -322,15 +322,13 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
{ {
dTHX; dTHX;
D_imp_dbh_from_sth; D_imp_dbh_from_sth;
int rc = 0;
char *errmsg; char *errmsg;
int num_params = DBIc_NUM_PARAMS(imp_sth); int num_params = DBIc_NUM_PARAMS(imp_sth);
int i; int i;
int retval = 0;
sqlite_trace(sth, (imp_xxh_t*)imp_sth, 3, "execute"); sqlite_trace(sth, (imp_xxh_t*)imp_sth, 3, "execute");
/* warn("execute\n"); */
if (!DBIc_ACTIVE(imp_dbh)) { if (!DBIc_ACTIVE(imp_dbh)) {
sqlite_error(sth, (imp_xxh_t*)imp_sth, -2, "attempt to execute on inactive database handle"); sqlite_error(sth, (imp_xxh_t*)imp_sth, -2, "attempt to execute on inactive database handle");
return -2; /* -> undef in SQLite.xsi */ return -2; /* -> undef in SQLite.xsi */
@ -338,7 +336,8 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
if (DBIc_ACTIVE(imp_sth)) { if (DBIc_ACTIVE(imp_sth)) {
sqlite_trace(sth, (imp_xxh_t*)imp_sth, 3, "execute still active, reset"); sqlite_trace(sth, (imp_xxh_t*)imp_sth, 3, "execute still active, reset");
if ((imp_sth->retval = sqlite3_reset(imp_sth->stmt)) != SQLITE_OK) { imp_sth->retval = sqlite3_reset(imp_sth->stmt);
if (imp_sth->retval != SQLITE_OK) {
char *errmsg = (char*)sqlite3_errmsg(imp_dbh->db); char *errmsg = (char*)sqlite3_errmsg(imp_dbh->db);
sqlite_error(sth, (imp_xxh_t*)imp_sth, imp_sth->retval, errmsg); sqlite_error(sth, (imp_xxh_t*)imp_sth, imp_sth->retval, errmsg);
return -2; /* -> undef in SQLite.xsi */ return -2; /* -> undef in SQLite.xsi */
@ -355,22 +354,22 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
if (!SvOK(value)) { if (!SvOK(value)) {
sqlite_trace(sth, (imp_xxh_t*)imp_sth, 5, "binding null"); sqlite_trace(sth, (imp_xxh_t*)imp_sth, 5, "binding null");
retval = sqlite3_bind_null(imp_sth->stmt, i+1); rc = sqlite3_bind_null(imp_sth->stmt, i+1);
} }
else if (sql_type >= SQL_NUMERIC && sql_type <= SQL_SMALLINT) { else if (sql_type >= SQL_NUMERIC && sql_type <= SQL_SMALLINT) {
#if defined(USE_64_BIT_INT) #if defined(USE_64_BIT_INT)
retval = sqlite3_bind_int64(imp_sth->stmt, i+1, SvIV(value)); rc = sqlite3_bind_int64(imp_sth->stmt, i+1, SvIV(value));
#else #else
retval = sqlite3_bind_int(imp_sth->stmt, i+1, SvIV(value)); rc = sqlite3_bind_int(imp_sth->stmt, i+1, SvIV(value));
#endif #endif
} }
else if (sql_type >= SQL_FLOAT && sql_type <= SQL_DOUBLE) { else if (sql_type >= SQL_FLOAT && sql_type <= SQL_DOUBLE) {
retval = sqlite3_bind_double(imp_sth->stmt, i+1, SvNV(value)); rc = sqlite3_bind_double(imp_sth->stmt, i+1, SvNV(value));
} }
else if (sql_type == SQL_BLOB) { else if (sql_type == SQL_BLOB) {
STRLEN len; STRLEN len;
char * data = SvPV(value, len); char * data = SvPV(value, len);
retval = sqlite3_bind_blob(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT); rc = sqlite3_bind_blob(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT);
} }
else { else {
#if 0 #if 0
@ -378,13 +377,13 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
const int numtype = looks_like_number(value); const int numtype = looks_like_number(value);
if ((numtype & (IS_NUMBER_IN_UV|IS_NUMBER_NOT_INT)) == IS_NUMBER_IN_UV) { if ((numtype & (IS_NUMBER_IN_UV|IS_NUMBER_NOT_INT)) == IS_NUMBER_IN_UV) {
#if defined(USE_64_BIT_INT) #if defined(USE_64_BIT_INT)
retval = sqlite3_bind_int64(imp_sth->stmt, i+1, SvIV(value)); rc = sqlite3_bind_int64(imp_sth->stmt, i+1, SvIV(value));
#else #else
retval = sqlite3_bind_int(imp_sth->stmt, i+1, SvIV(value)); rc = sqlite3_bind_int(imp_sth->stmt, i+1, SvIV(value));
#endif #endif
} }
else if ((numtype & (IS_NUMBER_NOT_INT|IS_NUMBER_INFINITY|IS_NUMBER_NAN)) == IS_NUMBER_NOT_INT) { else if ((numtype & (IS_NUMBER_NOT_INT|IS_NUMBER_INFINITY|IS_NUMBER_NAN)) == IS_NUMBER_NOT_INT) {
retval = sqlite3_bind_double(imp_sth->stmt, i+1, SvNV(value)); rc = sqlite3_bind_double(imp_sth->stmt, i+1, SvNV(value));
} }
else { else {
#endif #endif
@ -394,7 +393,7 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
sv_utf8_upgrade(value); sv_utf8_upgrade(value);
} }
data = SvPV(value, len); data = SvPV(value, len);
retval = sqlite3_bind_text(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT); rc = sqlite3_bind_text(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT);
#if 0 #if 0
} }
#endif #endif
@ -404,19 +403,17 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
SvREFCNT_dec(value); SvREFCNT_dec(value);
} }
SvREFCNT_dec(sql_type_sv); SvREFCNT_dec(sql_type_sv);
if (retval != SQLITE_OK) { if (rc != SQLITE_OK) {
sqlite_error(sth, (imp_xxh_t*)imp_sth, retval, (char*)sqlite3_errmsg(imp_dbh->db)); sqlite_error(sth, (imp_xxh_t*)imp_sth, rc, (char*)sqlite3_errmsg(imp_dbh->db));
return -4; /* -> undef in SQLite.xsi */ return -4; /* -> undef in SQLite.xsi */
} }
} }
if ( (!DBIc_is(imp_dbh, DBIcf_AutoCommit)) && (sqlite3_get_autocommit(imp_dbh->db)) ) { if ( (!DBIc_is(imp_dbh, DBIcf_AutoCommit)) && (sqlite3_get_autocommit(imp_dbh->db)) ) {
sqlite_trace(sth, (imp_xxh_t*)imp_sth, 2, "BEGIN TRAN"); sqlite_trace(sth, (imp_xxh_t*)imp_sth, 2, "BEGIN TRAN");
if ((retval = sqlite3_exec(imp_dbh->db, "BEGIN TRANSACTION", rc = sqlite3_exec(imp_dbh->db, "BEGIN TRANSACTION", NULL, NULL, &errmsg);
NULL, NULL, &errmsg)) if (rc != SQLITE_OK) {
!= SQLITE_OK) sqlite_error(sth, (imp_xxh_t*)imp_sth, rc, errmsg);
{
sqlite_error(sth, (imp_xxh_t*)imp_sth, retval, errmsg);
if (errmsg) if (errmsg)
sqlite3_free(errmsg); sqlite3_free(errmsg);
return -2; /* -> undef in SQLite.xsi */ return -2; /* -> undef in SQLite.xsi */
@ -625,14 +622,14 @@ sqlite_st_finish3 (SV *sth, imp_sth_t *imp_sth, int is_destroy)
/* warn("finish statement\n"); */ /* warn("finish statement\n"); */
if (!DBIc_ACTIVE(imp_sth)) if (!DBIc_ACTIVE(imp_sth))
return 1; return TRUE;
DBIc_ACTIVE_off(imp_sth); DBIc_ACTIVE_off(imp_sth);
av_clear(imp_sth->col_types); av_clear(imp_sth->col_types);
if (!DBIc_ACTIVE(imp_dbh)) /* no longer connected */ if (!DBIc_ACTIVE(imp_dbh)) /* no longer connected */
return 1; return TRUE;
if (is_destroy) { if (is_destroy) {
return TRUE; return TRUE;