DBD-EmpressNet
view release on metacpan or search on metacpan
se_return retval;
clear_error (sth);
if (se_Execute (imp_sth->st_num, DBIc_LongReadLen(imp_sth),
&nfields, &nrows) == SE_FAIL)
{
set_error (sth, "SQL Statement Execution Failed");
return -2;
}
imp_sth->nrows = nrows;
DBIc_NUM_FIELDS(imp_sth) = nfields;
/* DBI::ODBC indicates this MAY only be valid for SELECT */
/* I agree so I've implemented that way */
/* -1 is UNLIKELY to be returned by anything other than */
/* a select statement */
/**********
if (nrows == -1)
***********************/
DBIc_ACTIVE_on(imp_sth);
return nrows;
}
AV* dbd_st_fetch (
SV *sth,
imp_sth_t *imp_sth)
{
AV *av;
int chop_blanks;
SeRecord* field;
int index;
int num_fields;
unsigned char* ptr;
unsigned char* ptr2;
SeRecord* record;
se_return retval;
SV *sv;
clear_error (sth);
if (!DBIc_ACTIVE(imp_sth))
{
set_error(sth, "No Statement Active");
return Nullav;
}
retval = se_Fetch (imp_sth->st_num, &record, &num_fields);
/* se_Fetch may return SE_OK, SE_FAIL, SE_NOREC, or SE_LOCKEDREC */
/* all but SE_OK should set a message and return a NULL AV */
if (retval != SE_OK)
{
switch (retval)
{
case SE_NOREC:
dbd_st_finish (sth, imp_sth);
break;
case SE_LOCKEDREC:
set_error (sth, "Fetch: record locked");
break;
default:
set_error(sth, "Fetch: error");
break;
}
return Nullav;
}
DBIc_NUM_FIELDS(imp_sth) = num_fields;
/* lets start counting the rows as they are fetched! */
if (imp_sth->nrows == -1)
imp_sth->nrows = 0;
imp_sth->nrows++;
/* get the AV structure */
av = DBIS->get_fbav(imp_sth);
chop_blanks = DBIc_has(imp_sth, DBIcf_ChopBlanks);
index = 0;
for (field = record, index = 0;
field && index < num_fields;
field = field->next, index++)
{
sv = AvARRAY(av)[index];
/* NULL Data */
if (field->length == 0)
{
SvOK_off(sv);
}
/* if we want to chop blanks from none binary data we can */
/* do it here */
else if (chop_blanks && field->attr_type != SE_BINARY)
{
for (ptr = field->value; *ptr == ' '; ptr++);
for (ptr2 = &(field->value[field->length -1]);
*ptr2 == ' '; ptr2--);
if (ptr2 > ptr)
sv_setpvn (sv, (char*)ptr, ptr2-ptr+1);
else
SvOK_off(sv);
}
/* otherwise place the data in the output */
else
{
sv_setpvn(sv, (char*)field->value, field->length);
}
}
return av;
}
int dbd_st_finish (
SV *sth,
imp_sth_t *imp_sth)
{
( run in 2.077 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )