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:
parent
f3ef52b1ff
commit
4def999402
1 changed files with 59 additions and 50 deletions
109
dbdimp.c
109
dbdimp.c
|
@ -86,7 +86,7 @@ sqlite_db_login(SV *dbh, imp_dbh_t *imp_dbh, char *dbname, char *user, char *pas
|
||||||
int retval;
|
int retval;
|
||||||
char *errmsg = NULL;
|
char *errmsg = NULL;
|
||||||
|
|
||||||
if (DBIS->debug >= 3) {
|
if ( DBIS->debug >= 3 ) {
|
||||||
PerlIO_printf(DBILOGFP, " login '%s' (version %s)\n",
|
PerlIO_printf(DBILOGFP, " login '%s' (version %s)\n",
|
||||||
dbname, sqlite3_version);
|
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);
|
DBIc_ACTIVE_on(imp_dbh);
|
||||||
|
|
||||||
|
/*
|
||||||
if ( DBIc_WARN(imp_dbh) ) {
|
if ( DBIc_WARN(imp_dbh) ) {
|
||||||
warn("DBIc_WARN is on");
|
warn("DBIc_WARN is on");
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
else {
|
else {
|
||||||
warn("DBIc_WARN if off");
|
warn("DBIc_WARN if off");
|
||||||
}
|
}
|
||||||
|
if ( DBIc_is(imp_dbh, DBIcf_PrintWarn) ) {
|
||||||
|
warn("DBIcf_PrintWarn is on");
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -186,7 +189,12 @@ sqlite_db_destroy (SV *dbh, imp_dbh_t *imp_dbh)
|
||||||
{
|
{
|
||||||
dTHR;
|
dTHR;
|
||||||
if (DBIc_ACTIVE(imp_dbh)) {
|
if (DBIc_ACTIVE(imp_dbh)) {
|
||||||
|
/* warn("DBIc_ACTIVE is on"); */
|
||||||
sqlite_db_disconnect(dbh, imp_dbh);
|
sqlite_db_disconnect(dbh, imp_dbh);
|
||||||
|
/*
|
||||||
|
} else {
|
||||||
|
warn("DBIc_ACTIVE is off");
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
DBIc_IMPSET_off(imp_dbh);
|
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);
|
sqlite_trace(2, "prepare statement: %s", statement);
|
||||||
imp_sth->nrow = -1;
|
imp_sth->nrow = -1;
|
||||||
imp_sth->retval = SQLITE_OK;
|
imp_sth->retval = SQLITE_OK;
|
||||||
imp_sth->params = newAV();
|
imp_sth->params = newAV();
|
||||||
imp_sth->col_types = newAV();
|
imp_sth->col_types = newAV();
|
||||||
Newz(0, imp_sth->statement, strlen(statement)+1, char);
|
Newz(0, imp_sth->statement, strlen(statement)+1, char);
|
||||||
|
|
||||||
if ((retval = sqlite3_prepare_v2(imp_dbh->db, statement, -1, &(imp_sth->stmt), &extra))
|
if ((retval = sqlite3_prepare_v2(imp_dbh->db, statement, -1, &(imp_sth->stmt), &extra))
|
||||||
!= SQLITE_OK)
|
!= 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));
|
sqlite_error(sth, (imp_xxh_t*)imp_sth, retval, (char*)sqlite3_errmsg(imp_dbh->db));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* store the query for later re-use if required */
|
/* store the query for later re-use if required */
|
||||||
Copy(statement, imp_sth->statement, strlen(statement)+1, char);
|
Copy(statement, imp_sth->statement, strlen(statement)+1, char);
|
||||||
|
|
||||||
DBIc_NUM_PARAMS(imp_sth) = sqlite3_bind_parameter_count(imp_sth->stmt);
|
DBIc_NUM_PARAMS(imp_sth) = sqlite3_bind_parameter_count(imp_sth->stmt);
|
||||||
DBIc_NUM_FIELDS(imp_sth) = sqlite3_column_count(imp_sth->stmt);
|
DBIc_NUM_FIELDS(imp_sth) = sqlite3_column_count(imp_sth->stmt);
|
||||||
DBIc_IMPSET_on(imp_sth);
|
DBIc_IMPSET_on(imp_sth);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,7 +363,7 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
@ -388,7 +396,7 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
|
||||||
char * data = SvPV(value, len);
|
char * data = SvPV(value, len);
|
||||||
retval = sqlite3_bind_text(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT);
|
retval = sqlite3_bind_text(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
SvREFCNT_dec(value);
|
SvREFCNT_dec(value);
|
||||||
}
|
}
|
||||||
|
@ -398,7 +406,7 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (!DBIc_is(imp_dbh, DBIcf_AutoCommit)) && (!imp_dbh->in_tran) ) {
|
if ( (!DBIc_is(imp_dbh, DBIcf_AutoCommit)) && (!imp_dbh->in_tran) ) {
|
||||||
sqlite_trace(2, "BEGIN TRAN");
|
sqlite_trace(2, "BEGIN TRAN");
|
||||||
if ((retval = sqlite3_exec(imp_dbh->db, "BEGIN TRANSACTION",
|
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_dbh->in_tran = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
imp_sth->nrow = 0;
|
imp_sth->nrow = 0;
|
||||||
|
|
||||||
sqlite_trace(3, "Execute returned %d cols\n", DBIc_NUM_FIELDS(imp_sth));
|
sqlite_trace(3, "Execute returned %d cols\n", DBIc_NUM_FIELDS(imp_sth));
|
||||||
if (DBIc_NUM_FIELDS(imp_sth) == 0) {
|
if (DBIc_NUM_FIELDS(imp_sth) == 0) {
|
||||||
while ((imp_sth->retval = sqlite3_step(imp_sth->stmt)) != SQLITE_DONE) {
|
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); */
|
/* warn("Nrow: %d\n", imp_sth->nrow); */
|
||||||
return imp_sth->nrow;
|
return imp_sth->nrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
imp_sth->retval = sqlite3_step(imp_sth->stmt);
|
imp_sth->retval = sqlite3_step(imp_sth->stmt);
|
||||||
switch (imp_sth->retval) {
|
switch (imp_sth->retval) {
|
||||||
case SQLITE_ROW:
|
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);
|
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));
|
||||||
|
|
||||||
return TRUE;
|
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 */
|
/* store the type */
|
||||||
av_store(imp_sth->col_types, SvIV(col)-1, newSViv(sql_type));
|
av_store(imp_sth->col_types, SvIV(col)-1, newSViv(sql_type));
|
||||||
|
|
||||||
/* Allow default implementation to continue */
|
/* Allow default implementation to continue */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -514,21 +522,21 @@ sqlite_st_fetch (SV *sth, imp_sth_t *imp_sth)
|
||||||
if (!DBIc_ACTIVE(imp_sth)) {
|
if (!DBIc_ACTIVE(imp_sth)) {
|
||||||
return Nullav;
|
return Nullav;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imp_sth->retval == SQLITE_DONE) {
|
if (imp_sth->retval == SQLITE_DONE) {
|
||||||
sqlite_st_finish(sth, imp_sth);
|
sqlite_st_finish(sth, imp_sth);
|
||||||
return Nullav;
|
return Nullav;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imp_sth->retval != SQLITE_ROW) {
|
if (imp_sth->retval != SQLITE_ROW) {
|
||||||
/* error */
|
/* error */
|
||||||
sqlite_st_finish(sth, imp_sth);
|
sqlite_st_finish(sth, imp_sth);
|
||||||
sqlite_error(sth, (imp_xxh_t*)imp_sth, imp_sth->retval, (char*)sqlite3_errmsg(imp_dbh->db));
|
sqlite_error(sth, (imp_xxh_t*)imp_sth, imp_sth->retval, (char*)sqlite3_errmsg(imp_dbh->db));
|
||||||
return Nullav;
|
return Nullav;
|
||||||
}
|
}
|
||||||
|
|
||||||
imp_sth->nrow++;
|
imp_sth->nrow++;
|
||||||
|
|
||||||
av = DBIS->get_fbav(imp_sth);
|
av = DBIS->get_fbav(imp_sth);
|
||||||
for (i = 0; i < numFields; i++) {
|
for (i = 0; i < numFields; i++) {
|
||||||
int len;
|
int len;
|
||||||
|
@ -581,9 +589,9 @@ sqlite_st_fetch (SV *sth, imp_sth_t *imp_sth)
|
||||||
}
|
}
|
||||||
SvSETMAGIC(AvARRAY(av)[i]);
|
SvSETMAGIC(AvARRAY(av)[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
imp_sth->retval = sqlite3_step(imp_sth->stmt);
|
imp_sth->retval = sqlite3_step(imp_sth->stmt);
|
||||||
|
|
||||||
return av;
|
return av;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,22 +605,22 @@ 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)
|
||||||
{
|
{
|
||||||
D_imp_dbh_from_sth;
|
D_imp_dbh_from_sth;
|
||||||
|
|
||||||
/* warn("finish statement\n"); */
|
/* warn("finish statement\n"); */
|
||||||
if (!DBIc_ACTIVE(imp_sth))
|
if (!DBIc_ACTIVE(imp_sth))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
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 1;
|
||||||
|
|
||||||
if (is_destroy) {
|
if (is_destroy) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((imp_sth->retval = sqlite3_reset(imp_sth->stmt)) != SQLITE_OK) {
|
if ((imp_sth->retval = sqlite3_reset(imp_sth->stmt)) != SQLITE_OK) {
|
||||||
char *errmsg = (char*)sqlite3_errmsg(imp_dbh->db);
|
char *errmsg = (char*)sqlite3_errmsg(imp_dbh->db);
|
||||||
/* warn("finalize failed! %s\n", errmsg); */
|
/* 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;
|
int i,n;
|
||||||
|
|
||||||
if (!DBIc_ACTIVE(imp_sth)) {
|
if (!DBIc_ACTIVE(imp_sth)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* warn("fetch: %s\n", key); */
|
/* warn("fetch: %s\n", key); */
|
||||||
|
|
||||||
i = DBIc_NUM_FIELDS(imp_sth);
|
i = DBIc_NUM_FIELDS(imp_sth);
|
||||||
|
|
||||||
if (strEQ(key, "NAME")) {
|
if (strEQ(key, "NAME")) {
|
||||||
|
@ -764,7 +772,7 @@ sqlite_st_FETCH_attrib (SV *sth, imp_sth_t *imp_sth, SV *keysv)
|
||||||
if (fieldtype)
|
if (fieldtype)
|
||||||
av_store(av, n, newSVpv(fieldtype, 0));
|
av_store(av, n, newSVpv(fieldtype, 0));
|
||||||
else
|
else
|
||||||
av_store(av, n, newSVpv("VARCHAR", 0));
|
av_store(av, n, newSVpv("VARCHAR", 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strEQ(key, "NULLABLE")) {
|
else if (strEQ(key, "NULLABLE")) {
|
||||||
|
@ -787,7 +795,7 @@ sqlite_db_set_result(sqlite3_context *context, SV *result, int is_error )
|
||||||
{
|
{
|
||||||
STRLEN len;
|
STRLEN len;
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
if ( is_error ) {
|
if ( is_error ) {
|
||||||
s = SvPV(result, len);
|
s = SvPV(result, len);
|
||||||
sqlite3_result_error( context, s, 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 count;
|
||||||
int i;
|
int i;
|
||||||
SV *func;
|
SV *func;
|
||||||
|
|
||||||
func = sqlite3_user_data(context);
|
func = sqlite3_user_data(context);
|
||||||
|
|
||||||
ENTER;
|
ENTER;
|
||||||
SAVETMPS;
|
SAVETMPS;
|
||||||
|
|
||||||
PUSHMARK(SP);
|
PUSHMARK(SP);
|
||||||
for ( i=0; i < argc; i++ ) {
|
for ( i=0; i < argc; i++ ) {
|
||||||
SV *arg;
|
SV *arg;
|
||||||
STRLEN len = sqlite3_value_bytes(value[i]);
|
STRLEN len = sqlite3_value_bytes(value[i]);
|
||||||
int type = sqlite3_value_type(value[i]);
|
int type = sqlite3_value_type(value[i]);
|
||||||
|
|
||||||
/* warn("func dispatch type: %d, value: %s\n", type, sqlite3_value_text(value[i])); */
|
/* warn("func dispatch type: %d, value: %s\n", type, sqlite3_value_text(value[i])); */
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case SQLITE_INTEGER:
|
case SQLITE_INTEGER:
|
||||||
|
@ -872,9 +880,9 @@ sqlite_db_func_dispatcher(sqlite3_context *context, int argc, sqlite3_value **va
|
||||||
} else {
|
} else {
|
||||||
sqlite_db_set_result( context, POPs, 0 );
|
sqlite_db_set_result( context, POPs, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
PUTBACK;
|
PUTBACK;
|
||||||
|
|
||||||
FREETMPS;
|
FREETMPS;
|
||||||
LEAVE;
|
LEAVE;
|
||||||
}
|
}
|
||||||
|
@ -884,7 +892,7 @@ sqlite3_db_create_function( SV *dbh, const char *name, int argc, SV *func )
|
||||||
{
|
{
|
||||||
D_imp_dbh(dbh);
|
D_imp_dbh(dbh);
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
/* Copy the function reference */
|
/* Copy the function reference */
|
||||||
SV *func_sv = newSVsv(func);
|
SV *func_sv = newSVsv(func);
|
||||||
av_push( imp_dbh->functions, func_sv );
|
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));
|
aggr = sqlite3_aggregate_context (context, sizeof (aggrInfo));
|
||||||
if ( !aggr )
|
if ( !aggr )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ENTER;
|
ENTER;
|
||||||
SAVETMPS;
|
SAVETMPS;
|
||||||
|
|
||||||
/* initialize on first step */
|
/* initialize on first step */
|
||||||
if ( !aggr->inited ) {
|
if ( !aggr->inited ) {
|
||||||
sqlite_db_aggr_new_dispatcher( context, aggr );
|
sqlite_db_aggr_new_dispatcher( context, aggr );
|
||||||
|
@ -1036,10 +1044,10 @@ sqlite_db_aggr_finalize_dispatcher( sqlite3_context *context )
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
aggr = sqlite3_aggregate_context (context, sizeof (aggrInfo));
|
aggr = sqlite3_aggregate_context (context, sizeof (aggrInfo));
|
||||||
|
|
||||||
ENTER;
|
ENTER;
|
||||||
SAVETMPS;
|
SAVETMPS;
|
||||||
|
|
||||||
if ( !aggr ) {
|
if ( !aggr ) {
|
||||||
/* SQLite seems to refuse to create a context structure
|
/* SQLite seems to refuse to create a context structure
|
||||||
from finalize() */
|
from finalize() */
|
||||||
|
@ -1076,18 +1084,19 @@ sqlite_db_aggr_finalize_dispatcher( sqlite3_context *context )
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( aggr->err ) {
|
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 ); */
|
/* sqlite_db_set_result( context, aggr->err, 1 ); */
|
||||||
SvREFCNT_dec( aggr->err );
|
SvREFCNT_dec( aggr->err );
|
||||||
aggr->err = NULL;
|
aggr->err = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( aggr->aggr_inst ) {
|
if ( aggr->aggr_inst ) {
|
||||||
SvREFCNT_dec( aggr->aggr_inst );
|
SvREFCNT_dec( aggr->aggr_inst );
|
||||||
aggr->aggr_inst = NULL;
|
aggr->aggr_inst = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
FREETMPS;
|
FREETMPS;
|
||||||
LEAVE;
|
LEAVE;
|
||||||
}
|
}
|
||||||
|
@ -1097,7 +1106,7 @@ sqlite3_db_create_aggregate( SV *dbh, const char *name, int argc, SV *aggr_pkg )
|
||||||
{
|
{
|
||||||
D_imp_dbh(dbh);
|
D_imp_dbh(dbh);
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
/* Copy the aggregate reference */
|
/* Copy the aggregate reference */
|
||||||
SV *aggr_pkg_copy = newSVsv(aggr_pkg);
|
SV *aggr_pkg_copy = newSVsv(aggr_pkg);
|
||||||
av_push( imp_dbh->aggregates, aggr_pkg_copy );
|
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_step_dispatcher,
|
||||||
sqlite_db_aggr_finalize_dispatcher
|
sqlite_db_aggr_finalize_dispatcher
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( rv != SQLITE_OK )
|
if ( rv != SQLITE_OK )
|
||||||
{
|
{
|
||||||
croak( "sqlite_create_aggregate failed with error %s",
|
croak( "sqlite_create_aggregate failed with error %s",
|
||||||
|
|
Loading…
Add table
Reference in a new issue