DBD-SQLite2

 view release on metacpan or  search on metacpan

dbdimp.c  view on Meta::CPAN

    /* warn("exec ok - %d rows, %d cols\n", imp_sth->nrow, imp_sth->ncols); */
    DBIc_IMPSET_on(imp_sth);
    return 0;
}

int
sqlite2_st_rows (SV *sth, imp_sth_t *imp_sth)
{
    return imp_sth->nrow;
}

int
sqlite2_bind_ph (SV *sth, imp_sth_t *imp_sth,
                SV *param, SV *value, IV sql_type, SV *attribs,
                                int is_inout, IV maxlen)
{
    if (is_inout) {
        croak("InOut bind params not implemented");
    }
    /* warn("bind: %s => %s\n", SvPV_nolen(param), SvPV_nolen(value)); */
    if (sql_type >= SQL_NUMERIC && sql_type <= SQL_DOUBLE) {
        return av_store(imp_sth->params, SvIV(param) - 1, newSVnv(SvNV(value))) ? 1 : 0;
    }
    else {
        return av_store(imp_sth->params, SvIV(param) - 1, SvREFCNT_inc(value)) ? 1 : 0;
    }
}

AV *
sqlite2_st_fetch (SV *sth, imp_sth_t *imp_sth)
{
    AV *av;
    D_imp_dbh_from_sth;
    int numFields = DBIc_NUM_FIELDS(imp_sth);
    int chopBlanks = DBIc_is(imp_sth, DBIcf_ChopBlanks);
    int i;

    /* warn("current_entry == %d\nnumFields == %d\nnrow == %d",
        current_entry, numFields, imp_sth->nrow); */

    if (!DBIc_ACTIVE(imp_sth)) { /* [cpan #16451] */
        return Nullav;
    }

    if ((imp_sth->retval == SQLITE_DONE) || (imp_sth->retval == SQLITE_ERROR)) {
        sqlite2_st_finish(sth, imp_sth);
        return Nullav;
    }
    
    if (imp_sth->nrow == -1) {
        imp_sth->nrow++;
    }
    imp_sth->nrow++;
    
    av = DBIS->get_fbav(imp_sth);
    for (i = 0; i < numFields; i++) {
        char *val = imp_sth->results[i];
        /* warn("fetching: %d == %s\n", i, val); */
        if (val != NULL) {
            size_t len = strlen(val);
            char *decoded;
            if (chopBlanks) {
                val = savepv(val);
                while(len > 0 && val[len-1] == ' ') {
                    len--;
                }
                val[len] = '\0';
            }
            decoded = sqlite2_decode(imp_dbh, val, &len);
            sv_setpvn(AvARRAY(av)[i], decoded, len);
            Safefree(decoded);
            if (chopBlanks) Safefree(val);

            /* if (!imp_dbh->no_utf8_flag) {
            sv_utf8_encode(AvARRAY(av)[i]);
            } */
        }
        else {
            sv_setsv(AvARRAY(av)[i], &PL_sv_undef);
        }
    }
    _sqlite2_fetch_row(imp_sth);
    return av;
}

int
sqlite2_st_finish (SV *sth, imp_sth_t *imp_sth)
{
    /* warn("finish statement\n"); */
    if (DBIc_ACTIVE(imp_sth)) {
        char *errmsg;
        DBIc_ACTIVE_off(imp_sth);
        if ((imp_sth->retval = sqlite_finalize(imp_sth->vm, &errmsg) == SQLITE_ERROR)) {
            warn("finalize failed! %s\n", errmsg);
            sqlite2_error(sth, (imp_xxh_t*)imp_sth, imp_sth->retval, errmsg);
            sqlite_freemem(errmsg);
            return FALSE;
        }
    }
    return TRUE;
}

void
sqlite2_st_destroy (SV *sth, imp_sth_t *imp_sth)
{
    /* warn("destroy statement\n"); */
    if (DBIc_ACTIVE(imp_sth)) {
        sqlite2_st_finish(sth, imp_sth);
    }
    SvREFCNT_dec((SV*)imp_sth->sql);
    SvREFCNT_dec((SV*)imp_sth->params);
    DBIc_IMPSET_off(imp_sth);
}

int
sqlite2_st_blob_read (SV *sth, imp_sth_t *imp_sth,
                int field, long offset, long len, SV *destrv, long destoffset)
{
    return 0;
}

int
sqlite2_db_STORE_attrib (SV *dbh, imp_dbh_t *imp_dbh, SV *keysv, SV *valuesv)
{
    dTHR;
    char *key = SvPV_nolen(keysv);
    char *errmsg;
    int retval;

    if (strEQ(key, "AutoCommit")) {
        if (SvTRUE(valuesv)) {



( run in 0.363 second using v1.01-cache-2.11-cpan-df04353d9ac )