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

Whitespace and miscellaneous cleanup

This commit is contained in:
Adam Kennedy 2009-04-05 02:00:01 +00:00
parent f3ef52b1ff
commit 4def999402

109
dbdimp.c
View file

@ -86,7 +86,7 @@ sqlite_db_login(SV *dbh, imp_dbh_t *imp_dbh, char *dbname, char *user, char *pas
int retval;
char *errmsg = NULL;
if (DBIS->debug >= 3) {
if ( DBIS->debug >= 3 ) {
PerlIO_printf(DBILOGFP, " login '%s' (version %s)\n",
dbname, sqlite3_version);
}
@ -126,13 +126,16 @@ sqlite_db_login(SV *dbh, imp_dbh_t *imp_dbh, char *dbname, char *user, char *pas
DBIc_ACTIVE_on(imp_dbh);
/*
if ( DBIc_WARN(imp_dbh) ) {
warn("DBIc_WARN is on");
}
/*
else {
warn("DBIc_WARN if off");
}
if ( DBIc_is(imp_dbh, DBIcf_PrintWarn) ) {
warn("DBIcf_PrintWarn is on");
}
*/
return TRUE;
@ -186,7 +189,12 @@ sqlite_db_destroy (SV *dbh, imp_dbh_t *imp_dbh)
{
dTHR;
if (DBIc_ACTIVE(imp_dbh)) {
/* warn("DBIc_ACTIVE is on"); */
sqlite_db_disconnect(dbh, imp_dbh);
/*
} else {
warn("DBIc_ACTIVE is off");
*/
}
DBIc_IMPSET_off(imp_dbh);
}
@ -272,12 +280,12 @@ sqlite_st_prepare (SV *sth, imp_sth_t *imp_sth,
}
sqlite_trace(2, "prepare statement: %s", statement);
imp_sth->nrow = -1;
imp_sth->retval = SQLITE_OK;
imp_sth->params = newAV();
imp_sth->nrow = -1;
imp_sth->retval = SQLITE_OK;
imp_sth->params = newAV();
imp_sth->col_types = newAV();
Newz(0, imp_sth->statement, strlen(statement)+1, char);
if ((retval = sqlite3_prepare_v2(imp_dbh->db, statement, -1, &(imp_sth->stmt), &extra))
!= SQLITE_OK)
{
@ -287,14 +295,14 @@ sqlite_st_prepare (SV *sth, imp_sth_t *imp_sth,
sqlite_error(sth, (imp_xxh_t*)imp_sth, retval, (char*)sqlite3_errmsg(imp_dbh->db));
return FALSE;
}
/* store the query for later re-use if required */
Copy(statement, imp_sth->statement, strlen(statement)+1, char);
DBIc_NUM_PARAMS(imp_sth) = sqlite3_bind_parameter_count(imp_sth->stmt);
DBIc_NUM_FIELDS(imp_sth) = sqlite3_column_count(imp_sth->stmt);
DBIc_IMPSET_on(imp_sth);
return TRUE;
}
@ -355,7 +363,7 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
return FALSE;
}
}
for (i = 0; i < num_params; i++) {
SV *value = av_shift(imp_sth->params);
SV *sql_type_sv = av_shift(imp_sth->params);
@ -388,7 +396,7 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
char * data = SvPV(value, len);
retval = sqlite3_bind_text(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT);
}
if (value) {
SvREFCNT_dec(value);
}
@ -398,7 +406,7 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
return -4;
}
}
if ( (!DBIc_is(imp_dbh, DBIcf_AutoCommit)) && (!imp_dbh->in_tran) ) {
sqlite_trace(2, "BEGIN TRAN");
if ((retval = sqlite3_exec(imp_dbh->db, "BEGIN TRANSACTION",
@ -410,9 +418,9 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
}
imp_dbh->in_tran = TRUE;
}
imp_sth->nrow = 0;
sqlite_trace(3, "Execute returned %d cols\n", DBIc_NUM_FIELDS(imp_sth));
if (DBIc_NUM_FIELDS(imp_sth) == 0) {
while ((imp_sth->retval = sqlite3_step(imp_sth->stmt)) != SQLITE_DONE) {
@ -431,7 +439,7 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
/* warn("Nrow: %d\n", imp_sth->nrow); */
return imp_sth->nrow;
}
imp_sth->retval = sqlite3_step(imp_sth->stmt);
switch (imp_sth->retval) {
case SQLITE_ROW:
@ -486,7 +494,7 @@ sqlite_bind_ph (SV *sth, imp_sth_t *imp_sth,
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+1, newSViv(sql_type));
return TRUE;
}
@ -495,7 +503,7 @@ sqlite_bind_col(SV *sth, imp_sth_t *imp_sth, SV *col, SV *ref, IV sql_type, SV *
{
/* store the type */
av_store(imp_sth->col_types, SvIV(col)-1, newSViv(sql_type));
/* Allow default implementation to continue */
return 1;
}
@ -514,21 +522,21 @@ sqlite_st_fetch (SV *sth, imp_sth_t *imp_sth)
if (!DBIc_ACTIVE(imp_sth)) {
return Nullav;
}
if (imp_sth->retval == SQLITE_DONE) {
sqlite_st_finish(sth, imp_sth);
return Nullav;
}
if (imp_sth->retval != SQLITE_ROW) {
/* error */
sqlite_st_finish(sth, imp_sth);
sqlite_error(sth, (imp_xxh_t*)imp_sth, imp_sth->retval, (char*)sqlite3_errmsg(imp_dbh->db));
return Nullav;
}
imp_sth->nrow++;
av = DBIS->get_fbav(imp_sth);
for (i = 0; i < numFields; i++) {
int len;
@ -581,9 +589,9 @@ sqlite_st_fetch (SV *sth, imp_sth_t *imp_sth)
}
SvSETMAGIC(AvARRAY(av)[i]);
}
imp_sth->retval = sqlite3_step(imp_sth->stmt);
return av;
}
@ -597,22 +605,22 @@ int
sqlite_st_finish3 (SV *sth, imp_sth_t *imp_sth, int is_destroy)
{
D_imp_dbh_from_sth;
/* warn("finish statement\n"); */
if (!DBIc_ACTIVE(imp_sth))
return 1;
DBIc_ACTIVE_off(imp_sth);
av_clear(imp_sth->col_types);
if (!DBIc_ACTIVE(imp_dbh)) /* no longer connected */
return 1;
if (is_destroy) {
return TRUE;
}
if (is_destroy) {
return TRUE;
}
if ((imp_sth->retval = sqlite3_reset(imp_sth->stmt)) != SQLITE_OK) {
char *errmsg = (char*)sqlite3_errmsg(imp_dbh->db);
/* warn("finalize failed! %s\n", errmsg); */
@ -723,11 +731,11 @@ sqlite_st_FETCH_attrib (SV *sth, imp_sth_t *imp_sth, SV *keysv)
int i,n;
if (!DBIc_ACTIVE(imp_sth)) {
return NULL;
return NULL;
}
/* warn("fetch: %s\n", key); */
i = DBIc_NUM_FIELDS(imp_sth);
if (strEQ(key, "NAME")) {
@ -764,7 +772,7 @@ sqlite_st_FETCH_attrib (SV *sth, imp_sth_t *imp_sth, SV *keysv)
if (fieldtype)
av_store(av, n, newSVpv(fieldtype, 0));
else
av_store(av, n, newSVpv("VARCHAR", 0));
av_store(av, n, newSVpv("VARCHAR", 0));
}
}
else if (strEQ(key, "NULLABLE")) {
@ -787,7 +795,7 @@ sqlite_db_set_result(sqlite3_context *context, SV *result, int is_error )
{
STRLEN len;
char *s;
if ( is_error ) {
s = SvPV(result, len);
sqlite3_result_error( context, s, len );
@ -818,18 +826,18 @@ sqlite_db_func_dispatcher(sqlite3_context *context, int argc, sqlite3_value **va
int count;
int i;
SV *func;
func = sqlite3_user_data(context);
ENTER;
SAVETMPS;
PUSHMARK(SP);
for ( i=0; i < argc; i++ ) {
SV *arg;
STRLEN len = sqlite3_value_bytes(value[i]);
int type = sqlite3_value_type(value[i]);
/* warn("func dispatch type: %d, value: %s\n", type, sqlite3_value_text(value[i])); */
switch(type) {
case SQLITE_INTEGER:
@ -872,9 +880,9 @@ sqlite_db_func_dispatcher(sqlite3_context *context, int argc, sqlite3_value **va
} else {
sqlite_db_set_result( context, POPs, 0 );
}
PUTBACK;
FREETMPS;
LEAVE;
}
@ -884,7 +892,7 @@ sqlite3_db_create_function( SV *dbh, const char *name, int argc, SV *func )
{
D_imp_dbh(dbh);
int rv;
/* Copy the function reference */
SV *func_sv = newSVsv(func);
av_push( imp_dbh->functions, func_sv );
@ -974,10 +982,10 @@ sqlite_db_aggr_step_dispatcher (sqlite3_context *context,
aggr = sqlite3_aggregate_context (context, sizeof (aggrInfo));
if ( !aggr )
return;
ENTER;
SAVETMPS;
/* initialize on first step */
if ( !aggr->inited ) {
sqlite_db_aggr_new_dispatcher( context, aggr );
@ -1036,10 +1044,10 @@ sqlite_db_aggr_finalize_dispatcher( sqlite3_context *context )
int count = 0;
aggr = sqlite3_aggregate_context (context, sizeof (aggrInfo));
ENTER;
SAVETMPS;
if ( !aggr ) {
/* SQLite seems to refuse to create a context structure
from finalize() */
@ -1076,18 +1084,19 @@ sqlite_db_aggr_finalize_dispatcher( sqlite3_context *context )
}
if ( aggr->err ) {
warn( "DBD::SQLite: error in aggregator cannot be reported to SQLite: %s", SvPV_nolen( aggr->err ) );
warn( "DBD::SQLite: error in aggregator cannot be reported to SQLite: %s",
SvPV_nolen( aggr->err ) );
/* sqlite_db_set_result( context, aggr->err, 1 ); */
SvREFCNT_dec( aggr->err );
aggr->err = NULL;
}
if ( aggr->aggr_inst ) {
SvREFCNT_dec( aggr->aggr_inst );
aggr->aggr_inst = NULL;
}
FREETMPS;
LEAVE;
}
@ -1097,7 +1106,7 @@ sqlite3_db_create_aggregate( SV *dbh, const char *name, int argc, SV *aggr_pkg )
{
D_imp_dbh(dbh);
int rv;
/* Copy the aggregate reference */
SV *aggr_pkg_copy = newSVsv(aggr_pkg);
av_push( imp_dbh->aggregates, aggr_pkg_copy );
@ -1108,7 +1117,7 @@ sqlite3_db_create_aggregate( SV *dbh, const char *name, int argc, SV *aggr_pkg )
sqlite_db_aggr_step_dispatcher,
sqlite_db_aggr_finalize_dispatcher
);
if ( rv != SQLITE_OK )
{
croak( "sqlite_create_aggregate failed with error %s",