예제 #1
0
static void set_sqlite3_func_result(sqlite3_context * ctx, VALUE result)
{
  switch(TYPE(result)) {
    case T_NIL:
      sqlite3_result_null(ctx);
      break;
    case T_FIXNUM:
      sqlite3_result_int64(ctx, (sqlite3_int64)FIX2LONG(result));
      break;
    case T_BIGNUM:
#if SIZEOF_LONG < 8
      if (RBIGNUM_LEN(result) * SIZEOF_BDIGITS <= 8) {
          sqlite3_result_int64(ctx, NUM2LL(result));
          break;
      }
#endif
    case T_FLOAT:
      sqlite3_result_double(ctx, NUM2DBL(result));
      break;
    case T_STRING:
      sqlite3_result_text(
          ctx,
          (const char *)StringValuePtr(result),
          (int)RSTRING_LEN(result),
          SQLITE_TRANSIENT
      );
      break;
    default:
      rb_raise(rb_eRuntimeError, "can't return %s",
          rb_class2name(CLASS_OF(result)));
  }
}
예제 #2
0
/*
** Return values of columns for the row at which the memstat_cursor
** is currently pointing.
*/
static int memstatColumn(
  sqlite3_vtab_cursor *cur,   /* The cursor */
  sqlite3_context *ctx,       /* First argument to sqlite3_result_...() */
  int iCol                    /* Which column to return */
){
  memstat_cursor *pCur = (memstat_cursor*)cur;
  int i;
  assert( pCur->iRowid>0 && pCur->iRowid<=MSV_NROW );
  i = (int)pCur->iRowid - 1;
  if( (aMemstatColumn[i].mNull & (1<<iCol))!=0 ){
    return SQLITE_OK;
  }
  switch( iCol ){
    case MSV_COLUMN_NAME: {
      sqlite3_result_text(ctx, aMemstatColumn[i].zName, -1, SQLITE_STATIC);
      break;
    }
    case MSV_COLUMN_SCHEMA: {
      sqlite3_result_text(ctx, pCur->azDb[pCur->iDb], -1, 0);
      break;
    }
    case MSV_COLUMN_VALUE: {
      sqlite3_result_int64(ctx, pCur->aVal[0]);
      break;
    }
    case MSV_COLUMN_HIWTR: {
      sqlite3_result_int64(ctx, pCur->aVal[1]);
      break;
    }
  }
  return SQLITE_OK;
}
예제 #3
0
static int
vtxt_column (sqlite3_vtab_cursor * pCursor, sqlite3_context * pContext,
	     int column)
{
/* fetching value for the Nth column */
    int nCol = 1;
    int i;
    char buf[4096];
    int type;
    const char *value;
    VirtualTextCursorPtr cursor = (VirtualTextCursorPtr) pCursor;
    gaiaTextReaderPtr text = cursor->pVtab->reader;
    if (column == 0)
      {
	  /* the ROWNO column */
	  sqlite3_result_int (pContext, cursor->current_row);
	  return SQLITE_OK;
      }
    if (text->current_line_ready == 0)
	return SQLITE_ERROR;
    for (i = 0; i < text->max_fields; i++)
      {
	  if (nCol == column)
	    {
		if (!gaiaTextReaderFetchField (text, i, &type, &value))
		    sqlite3_result_null (pContext);
		else
		  {
		      if (type == VRTTXT_INTEGER)
			{
			    strcpy (buf, value);
			    text_clean_integer (buf);
#if defined(_WIN32) || defined(__MINGW32__)
/* CAVEAT - M$ runtime has non-standard functions for 64 bits */
			    sqlite3_result_int64 (pContext, _atoi64 (buf));
#else
			    sqlite3_result_int64 (pContext, atoll (buf));
#endif
			}
		      else if (type == VRTTXT_DOUBLE)
			{
			    strcpy (buf, value);
			    text_clean_double (buf);
			    sqlite3_result_double (pContext, atof (buf));
			}
		      else if (type == VRTTXT_TEXT)
			  sqlite3_result_text (pContext, value, strlen (value),
					       free);
		      else
			  sqlite3_result_null (pContext);
		  }
	    }
	  nCol++;
      }
    return SQLITE_OK;
}
예제 #4
0
static void set_sqlite3_func_result(sqlite3_context * ctx, VALUE result)
{
  switch(TYPE(result)) {
    case T_NIL:
      sqlite3_result_null(ctx);
      break;
    case T_FIXNUM:
      sqlite3_result_int64(ctx, (sqlite3_int64)FIX2LONG(result));
      break;
    case T_BIGNUM: {
#if SIZEOF_LONG < 8
      sqlite3_int64 num64;

      if (bignum_to_int64(result, &num64)) {
	  sqlite3_result_int64(ctx, num64);
	  break;
      }
#endif
    }
    case T_FLOAT:
      sqlite3_result_double(ctx, NUM2DBL(result));
      break;
    case T_STRING:
      if(CLASS_OF(result) == cSqlite3Blob
#ifdef HAVE_RUBY_ENCODING_H
              || rb_enc_get_index(result) == rb_ascii8bit_encindex()
#endif
        ) {
        sqlite3_result_blob(
            ctx,
            (const void *)StringValuePtr(result),
            (int)RSTRING_LEN(result),
            SQLITE_TRANSIENT
        );
      } else {
        sqlite3_result_text(
            ctx,
            (const char *)StringValuePtr(result),
            (int)RSTRING_LEN(result),
            SQLITE_TRANSIENT
        );
      }
      break;
    default:
      rb_raise(rb_eRuntimeError, "can't return %s",
          rb_class2name(CLASS_OF(result)));
  }
}
예제 #5
0
파일: m_sqlite.c 프로젝트: x768/fox-lang
static int sqlite_callback_return(Value v, sqlite3_context *ctx)
{
    const RefNode *r_type = fs->Value_type(v);
    if (r_type == fs->cls_int) {
        int err = FALSE;
        int64_t i64 = fs->Value_int64(v, &err);
        if (err) {
            fs->throw_errorf(mod_sqlite, "SQLiteError", "'INTEGER' out of range (-2^63 - 2^63-1)");
            return FALSE;
        }
        sqlite3_result_int64(ctx, i64);
    } else if (r_type == fs->cls_bool) {
        int i32 = Value_bool(v);
        sqlite3_result_int(ctx, i32);
    } else if (r_type == fs->cls_float) {
        double dval = Value_float2(v);
        sqlite3_result_double(ctx, dval);
    } else if (r_type == fs->cls_str) {
        RefStr *s = Value_vp(v);
        sqlite3_result_text(ctx, s->c, s->size, SQLITE_TRANSIENT);
    } else if (r_type == fs->cls_bytes) {
        RefStr *s = Value_vp(v);
        sqlite3_result_blob(ctx, s->c, s->size, SQLITE_TRANSIENT);
    } else if (r_type == fs->cls_null) {
        sqlite3_result_null(ctx);
    } else {
        fs->throw_errorf(fs->mod_lang, "TypeError", "Bool, Int, Float, Str, Bytes or Null required but %n", r_type);
        return FALSE;
    }
    return TRUE;
}
예제 #6
0
/*
** Implementation of the abs() function
*/
static void absFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
  assert( argc==1 );
  switch( sqlite3_value_type(argv[0]) ){
    case SQLITE_INTEGER: {
      i64 iVal = sqlite3_value_int64(argv[0]);
      if( iVal<0 ){
        if( (iVal<<1)==0 ){
          sqlite3_result_error(context, "integer overflow", -1);
          return;
        }
        iVal = -iVal;
      } 
      sqlite3_result_int64(context, iVal);
      break;
    }
    case SQLITE_NULL: {
      sqlite3_result_null(context);
      break;
    }
    default: {
      double rVal = sqlite3_value_double(argv[0]);
      if( rVal<0 ) rVal = -rVal;
      sqlite3_result_double(context, rVal);
      break;
    }
  }
}
예제 #7
0
static void sqlite_checksum_int8(
  sqlite3_context * ctx,
  int argc,
  sqlite3_value ** argv)
{
  assert(argc==1);
  const unsigned char * txt;
  size_t len;
  switch (sqlite3_value_type(argv[0])) {
  case SQLITE_NULL:
    txt = NULL;
    len = 0;
    break;
  case SQLITE_TEXT:
    txt = sqlite3_value_text(argv[0]);
    len = sqlite3_value_bytes(argv[0]);
    break;
    // hmmm... should I do something else?
  case SQLITE_INTEGER:
  case SQLITE_FLOAT:
  case SQLITE_BLOB:
  default:
    sqlite3_result_error(ctx, "expecting TEXT or NULL", -1);
    return;
  }
  sqlite3_result_int64(ctx, checksum_int8(txt, len));
}
예제 #8
0
파일: checkfreelist.c 프로젝트: cznic/cc
/*
** An SQL function invoked as follows:
**
**   sqlite_readint32(BLOB)           -- Decode 32-bit integer from start of blob
*/
static void readint_function(
  sqlite3_context *pCtx,
  int nArg,
  sqlite3_value **apArg
){
  const u8 *zBlob;
  int nBlob;
  int iOff = 0;
  u32 iRet = 0;

  if( nArg!=1 && nArg!=2 ){
    sqlite3_result_error(
        pCtx, "wrong number of arguments to function sqlite_readint32()", -1
    );
    return;
  }
  if( nArg==2 ){
    iOff = sqlite3_value_int(apArg[1]);
  }

  zBlob = sqlite3_value_blob(apArg[0]);
  nBlob = sqlite3_value_bytes(apArg[0]);

  if( nBlob>=(iOff+4) ){
    iRet = get4byte(&zBlob[iOff]);
  }

  sqlite3_result_int64(pCtx, (sqlite3_int64)iRet);
}
예제 #9
0
/*
 * Returns value for the column at position iCol (starting from 0).
 * Reads column data from ref-values table, filtered by ObjectID and sorted by PropertyID
 * For the sake of better performance, fetches required columns on demand, sequentially.
 *
 */
static int _column(sqlite3_vtab_cursor *pCursor, sqlite3_context *pContext, int iCol)
{
    int result = SQLITE_OK;
    struct flexi_VTabCursor *cur = (void *) pCursor;

    if (iCol == -1)
    {
        sqlite3_result_int64(pContext, cur->lObjectID);
        goto EXIT;
    }

    struct flexi_ClassDef_t *vtab = (void *) cur->base.pVtab;

    // First, check if column has been already loaded
    while (cur->iReadCol < iCol)
    {
        int colResult = sqlite3_step(cur->pPropertyIterator);
        if (colResult == SQLITE_DONE)
            break;
        if (colResult != SQLITE_ROW)
        {
            result = colResult;
            goto ONERROR;
        }
        sqlite3_int64 lPropID = sqlite3_column_int64(cur->pPropertyIterator, 1);
        if (lPropID < vtab->pProps[cur->iReadCol + 1].iPropID)
            continue;

        cur->iReadCol++;
        if (lPropID == vtab->pProps[cur->iReadCol].iPropID)
        {
            sqlite3_int64 lPropIdx = sqlite3_column_int64(cur->pPropertyIterator, 2);

            /*
             * No need in any special verification as we expect columns are sorted by property IDs, so
             * we just assume that once column index is OK, we can process this property data
             */

            cur->pCols[cur->iReadCol] = sqlite3_value_dup(sqlite3_column_value(cur->pPropertyIterator, 4));
        }
    }

    if (cur->pCols[iCol] == NULL || sqlite3_value_type(cur->pCols[iCol]) == SQLITE_NULL)
    {
        sqlite3_result_value(pContext, vtab->pProps[iCol].defaultValue);
    }
    else
    {
        sqlite3_result_value(pContext, cur->pCols[iCol]);
    }

    result = SQLITE_OK;
    goto EXIT;
    ONERROR:

    EXIT:
    // Map column number to property ID
    return result;
}
예제 #10
0
int xColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int col) {
  BaseCursor *pCur = (BaseCursor *)cur;
  const auto *pVtab = (VirtualTable *)cur->pVtab;
  if (col >= static_cast<int>(pVtab->content->columns.size())) {
    // Requested column index greater than column set size.
    return SQLITE_ERROR;
  }

  const auto &column_name = pVtab->content->columns[col].first;
  const auto &type = pVtab->content->columns[col].second;
  if (pCur->row >= pCur->data.size()) {
    // Request row index greater than row set size.
    return SQLITE_ERROR;
  }

  // Attempt to cast each xFilter-populated row/column to the SQLite type.
  const auto &value = pCur->data[pCur->row][column_name];
  if (pCur->data[pCur->row].count(column_name) == 0) {
    // Missing content.
    VLOG(1) << "Error " << column_name << " is empty";
    sqlite3_result_null(ctx);
  } else if (type == TEXT_TYPE) {
    sqlite3_result_text(ctx, value.c_str(), value.size(), SQLITE_STATIC);
  } else if (type == INTEGER_TYPE) {
    long afinite;
    if (!safeStrtol(value, 10, afinite) || afinite < INT_MIN ||
        afinite > INT_MAX) {
      VLOG(1) << "Error casting " << column_name << " (" << value
              << ") to INTEGER";
      sqlite3_result_null(ctx);
    } else {
      sqlite3_result_int(ctx, (int)afinite);
    }
  } else if (type == BIGINT_TYPE || type == UNSIGNED_BIGINT_TYPE) {
    long long afinite;
    if (!safeStrtoll(value, 10, afinite)) {
      VLOG(1) << "Error casting " << column_name << " (" << value
              << ") to BIGINT";
      sqlite3_result_null(ctx);
    } else {
      sqlite3_result_int64(ctx, afinite);
    }
  } else if (type == DOUBLE_TYPE) {
    char *end = nullptr;
    double afinite = strtod(value.c_str(), &end);
    if (end == nullptr || end == value.c_str() || *end != '\0') {
      afinite = 0;
      VLOG(1) << "Error casting " << column_name << " (" << value
              << ") to DOUBLE";
      sqlite3_result_null(ctx);
    } else {
      sqlite3_result_double(ctx, afinite);
    }
  } else {
    LOG(ERROR) << "Error unknown column type " << column_name;
  }

  return SQLITE_OK;
}
예제 #11
0
/*
** Implementation of the last_insert_rowid() SQL function.  The return
** value is the same as the sqlite3_last_insert_rowid() API function.
*/
static void last_insert_rowid(
  sqlite3_context *context, 
  int arg, 
  sqlite3_value **argv
){
  sqlite3 *db = sqlite3_user_data(context);
  sqlite3_result_int64(context, sqlite3_last_insert_rowid(db));
}
예제 #12
0
/*
** Retrieve a column of data.
*/
static int intarrayColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
  intarray_cursor *pCur = (intarray_cursor*)cur;
  intarray_vtab *pVtab = (intarray_vtab*)cur->pVtab;
  if( pCur->i>=0 && pCur->i<pVtab->pContent->n ){
    sqlite3_result_int64(ctx, pVtab->pContent->a[pCur->i]);
  }
  return SQLITE_OK;
}
예제 #13
0
파일: dbstat.c 프로젝트: 1018824313/sqlite
static int statColumn(
  sqlite3_vtab_cursor *pCursor, 
  sqlite3_context *ctx, 
  int i
){
  StatCursor *pCsr = (StatCursor *)pCursor;
  switch( i ){
    case 0:            /* name */
      sqlite3_result_text(ctx, pCsr->zName, -1, SQLITE_TRANSIENT);
      break;
    case 1:            /* path */
      sqlite3_result_text(ctx, pCsr->zPath, -1, SQLITE_TRANSIENT);
      break;
    case 2:            /* pageno */
      sqlite3_result_int64(ctx, pCsr->iPageno);
      break;
    case 3:            /* pagetype */
      sqlite3_result_text(ctx, pCsr->zPagetype, -1, SQLITE_STATIC);
      break;
    case 4:            /* ncell */
      sqlite3_result_int(ctx, pCsr->nCell);
      break;
    case 5:            /* payload */
      sqlite3_result_int(ctx, pCsr->nPayload);
      break;
    case 6:            /* unused */
      sqlite3_result_int(ctx, pCsr->nUnused);
      break;
    case 7:            /* mx_payload */
      sqlite3_result_int(ctx, pCsr->nMxPayload);
      break;
    case 8:            /* pgoffset */
      sqlite3_result_int64(ctx, pCsr->iOffset);
      break;
    case 9:            /* pgsize */
      sqlite3_result_int(ctx, pCsr->szPage);
      break;
    default: {          /* schema */
      sqlite3 *db = sqlite3_context_db_handle(ctx);
      int iDb = pCsr->iDb;
      sqlite3_result_text(ctx, db->aDb[iDb].zName, -1, SQLITE_STATIC);
      break;
    }
  }
  return SQLITE_OK;
}
/*
** Retrieve a column of data.
*/
static int intarrayColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int column) {
  intarray_cursor *pCur = (intarray_cursor*)cur;
  intarray_vtab *table = (intarray_vtab*)cur->pVtab;
  sqlite3_intarray *arr = table->intarray;
  if (pCur->i >= 0 && pCur->i < arr->n) {
    sqlite3_result_int64(ctx, arr->a[pCur->i]);
  }
  return SQLITE_OK;
}
예제 #15
0
파일: func.c 프로젝트: kaomte/sqlcipher
/*
** Implementation of the last_insert_rowid() SQL function.  The return
** value is the same as the sqlite3_last_insert_rowid() API function.
*/
static void last_insert_rowid(
  sqlite3_context *context, 
  int NotUsed, 
  sqlite3_value **NotUsed2
){
  sqlite3 *db = sqlite3_context_db_handle(context);
  UNUSED_PARAMETER2(NotUsed, NotUsed2);
  sqlite3_result_int64(context, sqlite3_last_insert_rowid(db));
}
예제 #16
0
static
void OGR2SQLITE_ogr_geocode_set_result(sqlite3_context* pContext,
                                       OGRLayerH hLayer,
                                       const char* pszField)
{
    if( hLayer == NULL )
        sqlite3_result_null (pContext);
    else
    {
        OGRLayer* poLayer = (OGRLayer*)hLayer;
        OGRFeatureDefn* poFDefn = poLayer->GetLayerDefn();
        OGRFeature* poFeature = poLayer->GetNextFeature();
        int nIdx = -1;
        if( poFeature == NULL )
            sqlite3_result_null (pContext);
        else if( strcmp(pszField, "geometry") == 0 &&
                 poFeature->GetGeometryRef() != NULL )
        {
            GByte* pabyGeomBLOB = NULL;
            int nGeomBLOBLen = 0;
            if( OGRSQLiteLayer::ExportSpatiaLiteGeometry(
                        poFeature->GetGeometryRef(), 4326, wkbNDR, FALSE, FALSE, FALSE,
                        &pabyGeomBLOB,
                        &nGeomBLOBLen ) != CE_None )
            {
                sqlite3_result_null (pContext);
            }
            else
            {
                sqlite3_result_blob (pContext, pabyGeomBLOB, nGeomBLOBLen, CPLFree);
            }
        }
        else if( (nIdx = poFDefn->GetFieldIndex(pszField)) >= 0 &&
                 poFeature->IsFieldSet(nIdx) )
        {
            OGRFieldType eType = poFDefn->GetFieldDefn(nIdx)->GetType();
            if( eType == OFTInteger )
                sqlite3_result_int(pContext,
                                   poFeature->GetFieldAsInteger(nIdx));
            else if( eType == OFTInteger64 )
                sqlite3_result_int64(pContext,
                                     poFeature->GetFieldAsInteger64(nIdx));
            else if( eType == OFTReal )
                sqlite3_result_double(pContext,
                                      poFeature->GetFieldAsDouble(nIdx));
            else
                sqlite3_result_text(pContext,
                                    poFeature->GetFieldAsString(nIdx),
                                    -1, SQLITE_TRANSIENT);
        }
        else
            sqlite3_result_null (pContext);
        delete poFeature;
        OGRGeocodeFreeResult(hLayer);
    }
}
예제 #17
0
int LinkerColumnsWithNameVirtualTable::Column(void *cursor, sqlite3_context *ctx, int i)
{
    struct lfcurs * pCur = (struct lfcurs *)cursor;
    if( pCur->i>=0 && pCur->i < rows)
        if (i < columns-1)
            sqlite3_result_int64(ctx, data[pCur->i*(columns-1) + i]);
        else
            sqlite3_result_text(ctx, (char *)names[pCur->i]->c_str(), names[pCur->i]->size(), SQLITE_STATIC);
    return SQLITE_OK;
}
예제 #18
0
void
TiVoRandomSeedFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
{
	int64_t r, seed;

	if( argc != 1 || sqlite3_value_type(argv[0]) != SQLITE_INTEGER )
		return;
	seed = sqlite3_value_int64(argv[0]);
	seedRandomness(sizeof(r), &r, seed);
	sqlite3_result_int64(context, r);
}
예제 #19
0
파일: Rinit.c 프로젝트: duncantl/RSQLiteUDF
/*
** largest integer value not greater than argument
*/
void myfloorFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
  double rVal=0.0;

  switch( sqlite3_value_type(argv[0]) ){
    case SQLITE_INTEGER: {
      i64 iVal = sqlite3_value_int64(argv[0]);
      sqlite3_result_int64(context, iVal);
      break;
    }
    case SQLITE_NULL: {
      sqlite3_result_null(context);
      break;
    }
    default: {
      rVal = sqlite3_value_double(argv[0]);
      sqlite3_result_int64(context, (i64) floor(rVal));
      break;
    }
  }
}
예제 #20
0
/*
** Implementation of random().  Return a random integer.  
*/
static void randomFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  sqlite_int64 r;
  sqlite3Randomness(sizeof(r), &r);
  if( (r<<1)==0 ) r = 0;  /* Prevent 0x8000.... as the result so that we */
                          /* can always do abs() of the result */
  sqlite3_result_int64(context, r);
}
예제 #21
0
static void sumFinalize(sqlite3_context *context){
  SumCtx *p;
  p = sqlite3_aggregate_context(context, 0);
  if( p && p->cnt>0 ){
    if( p->approx ){
      sqlite3_result_double(context, p->sum);
    }else{
      sqlite3_result_int64(context, (i64)p->sum);
    }
  }
}
예제 #22
0
/*
** Implementation of random().  Return a random integer.  
*/
static void randomFunc(
  sqlite3_context *context,
  int NotUsed,
  sqlite3_value **NotUsed2
){
  sqlite_int64 r;
  UNUSED_PARAMETER2(NotUsed, NotUsed2);
  sqlite3_randomness(sizeof(r), &r);
  if( (r<<1)==0 ) r = 0;  /* Prevent 0x8000.... as the result so that we */
                          /* can always do abs() of the result */
  sqlite3_result_int64(context, r);
}
ikptr
ik_sqlite3_result_int64 (ikptr s_context, ikptr s_retval, ikpcb * pcb)
{
#ifdef HAVE_SQLITE3_RESULT_INT64
  sqlite3_context *	context = IK_SQLITE_CONTEXT(s_context);
  sqlite3_int64		retval	= ik_integer_to_sint64(s_retval);
  sqlite3_result_int64(context, retval);
  return IK_VOID_OBJECT;
#else
  feature_failure(__func__);
#endif
}
예제 #24
0
static void callCastedDoubleFunc(sqlite3_context* context,
                                 int argc,
                                 sqlite3_value** argv,
                                 DoubleDoubleFunction f) {
  double rVal = 0.0;
  assert(argc == 1);
  switch (sqlite3_value_type(argv[0])) {
  case SQLITE_INTEGER: {
    int64_t iVal = sqlite3_value_int64(argv[0]);
    sqlite3_result_int64(context, iVal);
    break;
  }
  case SQLITE_NULL:
    sqlite3_result_null(context);
    break;
  default:
    rVal = sqlite3_value_double(argv[0]);
    sqlite3_result_int64(context, (int64_t)f(rVal));
    break;
  }
}
예제 #25
0
파일: func.c 프로젝트: blingstorm/sqlcipher
/*
** Implementation of the last_insert_rowid() SQL function.  The return
** value is the same as the sqlite3_last_insert_rowid() API function.
*/
static void last_insert_rowid(
  sqlite3_context *context, 
  int NotUsed, 
  sqlite3_value **NotUsed2
){
  sqlite3 *db = sqlite3_context_db_handle(context);
  UNUSED_PARAMETER2(NotUsed, NotUsed2);
  /* IMP: R-51513-12026 The last_insert_rowid() SQL function is a
  ** wrapper around the sqlite3_last_insert_rowid() C/C++ interface
  ** function. */
  sqlite3_result_int64(context, sqlite3_last_insert_rowid(db));
}
예제 #26
0
static int
vdbf_column (sqlite3_vtab_cursor * pCursor, sqlite3_context * pContext,
	     int column)
{
/* fetching value for the Nth column */
    int nCol = 1;
    gaiaDbfFieldPtr pFld;
    VirtualDbfCursorPtr cursor = (VirtualDbfCursorPtr) pCursor;
    if (column == 0)
      {
	  /* the PRIMARY KEY column */
	  sqlite3_result_int (pContext, cursor->current_row);
	  return SQLITE_OK;
      }
    pFld = cursor->pVtab->dbf->Dbf->First;
    while (pFld)
      {
	  /* column values */
	  if (nCol == column)
	    {
		if (!(pFld->Value))
		    sqlite3_result_null (pContext);
		else
		  {
		      switch (pFld->Value->Type)
			{
			case GAIA_INT_VALUE:
			    sqlite3_result_int64 (pContext,
						  pFld->Value->IntValue);
			    break;
			case GAIA_DOUBLE_VALUE:
			    sqlite3_result_double (pContext,
						   pFld->Value->DblValue);
			    break;
			case GAIA_TEXT_VALUE:
			    sqlite3_result_text (pContext,
						 pFld->Value->TxtValue,
						 strlen (pFld->Value->TxtValue),
						 SQLITE_STATIC);
			    break;
			default:
			    sqlite3_result_null (pContext);
			    break;
			}
		  }
		break;
	    }
	  nCol++;
	  pFld = pFld->Next;
      }
    return SQLITE_OK;
}
예제 #27
0
파일: func.c 프로젝트: blingstorm/sqlcipher
static void sumFinalize(sqlite3_context *context){
  SumCtx *p;
  p = sqlite3_aggregate_context(context, 0);
  if( p && p->cnt>0 ){
    if( p->overflow ){
      sqlite3_result_error(context,"integer overflow",-1);
    }else if( p->approx ){
      sqlite3_result_double(context, p->rSum);
    }else{
      sqlite3_result_int64(context, p->iSum);
    }
  }
}
예제 #28
0
void ObjToSqliteContextValue(Tcl_Obj *objP, sqlite3_context *sqlctxP)
{
    unsigned char *data;
    int len;
    if (objP->typePtr) {
        /*
         * Note there is no return code checking here. Once the typePtr
         * is checked, the corresponding Tcl_Get* function should
         * always succeed.
         */

        if (objP->typePtr == gTclStringTypeP) {
            /*
             * Do nothing, fall thru below to handle as default type.
             * This check is here just so the most common case of text
             * columns does not needlessly go through other type checks.
             */
        } else if (objP->typePtr == gTclIntTypeP) {
            int ival;
            Tcl_GetIntFromObj(NULL, objP, &ival);
            sqlite3_result_int(sqlctxP, ival);
            return;
        } else if (objP->typePtr == gTclWideIntTypeP) {
            Tcl_WideInt i64val;
            Tcl_GetWideIntFromObj(NULL, objP, &i64val);
            sqlite3_result_int64(sqlctxP, i64val);
            return;
        } else if (objP->typePtr == gTclDoubleTypeP) {
            double dval;
            Tcl_GetDoubleFromObj(NULL, objP, &dval);
            sqlite3_result_double(sqlctxP, dval);
            return;
        } else if (objP->typePtr == gTclBooleanTypeP ||
                   objP->typePtr == gTclBooleanStringTypeP) {
            int bval;
            Tcl_GetBooleanFromObj(NULL, objP, &bval);
            sqlite3_result_int(sqlctxP, bval);
            return;
        } else if (objP->typePtr == gTclByteArrayTypeP) {
            /* TBD */
            data = Tcl_GetByteArrayFromObj(objP, &len);
            sqlite3_result_blob(sqlctxP, data, len, SQLITE_TRANSIENT);
            return;
        }
    }

    /* Handle everything else as text by default */
    data = (unsigned char *)Tcl_GetStringFromObj(objP, &len);
    sqlite3_result_text(sqlctxP, data, len, SQLITE_TRANSIENT);
}
예제 #29
0
/*
** xColumn - Return a column value.
*/
static int fts3auxColumnMethod(
  sqlite3_vtab_cursor *pCursor,   /* Cursor to retrieve value from */
  sqlite3_context *pContext,      /* Context for sqlite3_result_xxx() calls */
  int iCol                        /* Index of column to read value from */
){
  Fts3auxCursor *p = (Fts3auxCursor *)pCursor;

  assert( p->isEof==0 );
  if( iCol==0 ){        /* Column "term" */
    sqlite3_result_text(pContext, p->csr.zTerm, p->csr.nTerm, SQLITE_TRANSIENT);
  }else if( iCol==1 ){  /* Column "col" */
    if( p->iCol ){
      sqlite3_result_int(pContext, p->iCol-1);
    }else{
      sqlite3_result_text(pContext, "*", -1, SQLITE_STATIC);
    }
  }else if( iCol==2 ){  /* Column "documents" */
    sqlite3_result_int64(pContext, p->aStat[p->iCol].nDoc);
  }else{                /* Column "occurrences" */
    sqlite3_result_int64(pContext, p->aStat[p->iCol].nOcc);
  }

  return SQLITE_OK;
}
예제 #30
0
extern void     my_ceil(sqlite3_context * context, 
                        int               argc, 
                        sqlite3_value  ** argv) {
    double  val;
    int     typ;
        
    typ = sqlite3_value_type(argv[0]);
    if (typ == SQLITE_NULL) {
      sqlite3_result_null(context);
    } else {
      if ((typ == SQLITE_INTEGER)
          || (typ == SQLITE_FLOAT)) {
        val = sqlite3_value_double(argv[0]);
        sqlite3_result_int64(context, (long)ceil(val));
      } else {
        //Wrong input 
        sqlite3_result_int(context, 0);
      } 
    } 
}