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:
parent
2fa57ee8fa
commit
c377a44184
1 changed files with 33 additions and 36 deletions
69
dbdimp.c
69
dbdimp.c
|
@ -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 */
|
||||||
|
@ -346,31 +345,31 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < num_params; i++) {
|
for (i = 0; i < num_params; i++) {
|
||||||
SV *value = av_shift(imp_sth->params);
|
SV *value = av_shift(imp_sth->params);
|
||||||
SV *sql_type_sv = av_shift(imp_sth->params);
|
SV *sql_type_sv = av_shift(imp_sth->params);
|
||||||
int sql_type = SvIV(sql_type_sv);
|
int sql_type = SvIV(sql_type_sv);
|
||||||
|
|
||||||
sqlite_trace(sth, (imp_xxh_t*)imp_sth, 4, "params left in 0x%p: %d", imp_sth->params, 1+av_len(imp_sth->params));
|
sqlite_trace(sth, (imp_xxh_t*)imp_sth, 4, "params left in 0x%p: %d", imp_sth->params, 1+av_len(imp_sth->params));
|
||||||
sqlite_trace(sth, (imp_xxh_t*)imp_sth, 4, "bind %d type %d as %s", i, sql_type, SvPV_nolen_undef_ok(value));
|
sqlite_trace(sth, (imp_xxh_t*)imp_sth, 4, "bind %d type %d as %s", i, sql_type, SvPV_nolen_undef_ok(value));
|
||||||
|
|
||||||
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 */
|
||||||
|
@ -462,7 +459,7 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
sqlite_st_rows (SV *sth, imp_sth_t *imp_sth)
|
sqlite_st_rows(SV *sth, imp_sth_t *imp_sth)
|
||||||
{
|
{
|
||||||
return imp_sth->nrow;
|
return imp_sth->nrow;
|
||||||
}
|
}
|
||||||
|
@ -473,9 +470,9 @@ sqlite_st_rows (SV *sth, imp_sth_t *imp_sth)
|
||||||
* and so we can't lose these params
|
* and so we can't lose these params
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
sqlite_bind_ph (SV *sth, imp_sth_t *imp_sth,
|
sqlite_bind_ph(SV *sth, imp_sth_t *imp_sth,
|
||||||
SV *param, SV *value, IV sql_type, SV *attribs,
|
SV *param, SV *value, IV sql_type, SV *attribs,
|
||||||
int is_inout, IV maxlen)
|
int is_inout, IV maxlen)
|
||||||
{
|
{
|
||||||
dTHX;
|
dTHX;
|
||||||
int pos;
|
int pos;
|
||||||
|
@ -485,7 +482,7 @@ sqlite_bind_ph (SV *sth, imp_sth_t *imp_sth,
|
||||||
paramstring = SvPV(param, len);
|
paramstring = SvPV(param, len);
|
||||||
if(paramstring[len] == 0 && strlen(paramstring) == len) {
|
if(paramstring[len] == 0 && strlen(paramstring) == len) {
|
||||||
pos = sqlite3_bind_parameter_index(imp_sth->stmt, paramstring);
|
pos = sqlite3_bind_parameter_index(imp_sth->stmt, paramstring);
|
||||||
if (pos==0) {
|
if (pos == 0) {
|
||||||
char* const errmsg = form("Unknown named parameter: %s", paramstring);
|
char* const errmsg = form("Unknown named parameter: %s", paramstring);
|
||||||
sqlite_error(sth, (imp_xxh_t*)imp_sth, -2, errmsg);
|
sqlite_error(sth, (imp_xxh_t*)imp_sth, -2, errmsg);
|
||||||
return FALSE; /* -> &sv_no in SQLite.xsi */
|
return FALSE; /* -> &sv_no in SQLite.xsi */
|
||||||
|
@ -505,7 +502,7 @@ sqlite_bind_ph (SV *sth, imp_sth_t *imp_sth,
|
||||||
}
|
}
|
||||||
pos = 2 * (SvIV(param) - 1);
|
pos = 2 * (SvIV(param) - 1);
|
||||||
sqlite_trace(sth, (imp_xxh_t*)imp_sth, 3, "bind into 0x%p: %d => %s (%d) pos %d\n",
|
sqlite_trace(sth, (imp_xxh_t*)imp_sth, 3, "bind into 0x%p: %d => %s (%d) pos %d\n",
|
||||||
imp_sth->params, SvIV(param), SvPV_nolen_undef_ok(value), sql_type, pos);
|
imp_sth->params, SvIV(param), SvPV_nolen_undef_ok(value), sql_type, pos);
|
||||||
av_store(imp_sth->params, pos, SvREFCNT_inc(value));
|
av_store(imp_sth->params, pos, SvREFCNT_inc(value));
|
||||||
av_store(imp_sth->params, pos+1, newSViv(sql_type));
|
av_store(imp_sth->params, pos+1, newSViv(sql_type));
|
||||||
|
|
||||||
|
@ -525,7 +522,7 @@ sqlite_bind_col(SV *sth, imp_sth_t *imp_sth, SV *col, SV *ref, IV sql_type, SV *
|
||||||
}
|
}
|
||||||
|
|
||||||
AV *
|
AV *
|
||||||
sqlite_st_fetch (SV *sth, imp_sth_t *imp_sth)
|
sqlite_st_fetch(SV *sth, imp_sth_t *imp_sth)
|
||||||
{
|
{
|
||||||
dTHX;
|
dTHX;
|
||||||
|
|
||||||
|
@ -582,14 +579,14 @@ sqlite_st_fetch (SV *sth, imp_sth_t *imp_sth)
|
||||||
len = sqlite3_column_bytes(imp_sth->stmt, i);
|
len = sqlite3_column_bytes(imp_sth->stmt, i);
|
||||||
if (chopBlanks) {
|
if (chopBlanks) {
|
||||||
while((len > 0) && (val[len-1] == ' ')) {
|
while((len > 0) && (val[len-1] == ' ')) {
|
||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sv_setpvn(AvARRAY(av)[i], val, len);
|
sv_setpvn(AvARRAY(av)[i], val, len);
|
||||||
if (imp_dbh->unicode) {
|
if (imp_dbh->unicode) {
|
||||||
SvUTF8_on(AvARRAY(av)[i]);
|
SvUTF8_on(AvARRAY(av)[i]);
|
||||||
} else {
|
} else {
|
||||||
SvUTF8_off(AvARRAY(av)[i]);
|
SvUTF8_off(AvARRAY(av)[i]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SQLITE_BLOB:
|
case SQLITE_BLOB:
|
||||||
|
@ -611,13 +608,13 @@ sqlite_st_fetch (SV *sth, imp_sth_t *imp_sth)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
sqlite_st_finish (SV *sth, imp_sth_t *imp_sth)
|
sqlite_st_finish(SV *sth, imp_sth_t *imp_sth)
|
||||||
{
|
{
|
||||||
return sqlite_st_finish3(sth, imp_sth, 0);
|
return sqlite_st_finish3(sth, imp_sth, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
sqlite_st_finish3 (SV *sth, imp_sth_t *imp_sth, int is_destroy)
|
sqlite_st_finish3(SV *sth, imp_sth_t *imp_sth, int is_destroy)
|
||||||
{
|
{
|
||||||
dTHX;
|
dTHX;
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
|
Loading…
Add table
Reference in a new issue