Пример #1
0
/*
 ** The implementation of the sqlite_record() function. This function accepts
 ** a single argument of any type. The return value is a formatted database
 ** record (a blob) containing the argument value.
 **
 ** This is used to convert the value stored in the 'sample' column of the
 ** sqlite_stat3 table to the record format SQLite uses internally.
 */
static void recordFunc(
                       sqlite3_context *context,
                       int argc,
                       sqlite3_value **argv
                       ){
    const int file_format = 1;
    int iSerial;                    /* Serial type */
    int nSerial;                    /* Bytes of space for iSerial as varint */
    int nVal;                       /* Bytes of space required for argv[0] */
    int nRet;
    sqlite3 *db;
    u8 *aRet;
    
    UNUSED_PARAMETER( argc );
    iSerial = sqlite3VdbeSerialType(argv[0], file_format);
    nSerial = sqlite3VarintLen(iSerial);
    nVal = sqlite3VdbeSerialTypeLen(iSerial);
    db = sqlite3_context_db_handle(context);
    
    nRet = 1 + nSerial + nVal;
    aRet = sqlite3DbMallocRaw(db, nRet);
    if( aRet==0 ){
        sqlite3_result_error_nomem(context);
    }else{
        aRet[0] = nSerial+1;
        sqlite3PutVarint(&aRet[1], iSerial);
        sqlite3VdbeSerialPut(&aRet[1+nSerial], nVal, argv[0], file_format);
        sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
        sqlite3DbFree(db, aRet);
    }
}
Пример #2
0
/*
** Write a single varint, value iVal, to file-descriptor pFile. Return
** SQLITE_OK if successful, or an SQLite error code if some error occurs.
**
** The value of *piOffset when this function is called is used as the byte
** offset in file pFile to write to. Before returning, *piOffset is 
** incremented by the number of bytes written.
*/
static int vdbeSorterWriteVarint(
  sqlite3_file *pFile,            /* File to write to */
  i64 iVal,                       /* Value to write as a varint */
  i64 *piOffset                   /* IN/OUT: Write offset in file pFile */
){
  u8 aVarint[9];                  /* Buffer large enough for a varint */
  int nVarint;                    /* Number of used bytes in varint */
  int rc;                         /* Result of write() call */

  nVarint = sqlite3PutVarint(aVarint, iVal);
  rc = sqlite3OsWrite(pFile, aVarint, nVarint, *piOffset);
  *piOffset += nVarint;

  return rc;
}
Пример #3
0
/*
** Write value iVal encoded as a varint to the file-write object. Return 
** SQLITE_OK if successful, or an SQLite error code if an error occurs.
*/
static void fileWriterWriteVarint(FileWriter *p, u64 iVal){
  int nByte; 
  u8 aByte[10];
  nByte = sqlite3PutVarint(aByte, iVal);
  fileWriterWrite(p, aByte, nByte);
}