DBD-SQLeet

 view release on metacpan or  search on metacpan

sqlite3.c  view on Meta::CPAN

/*
** Convert zDate into one or more integers according to the conversion
** specifier zFormat.
**
** zFormat[] contains 4 characters for each integer converted, except for
** the last integer which is specified by three characters.  The meaning
** of a four-character format specifiers ABCD is:
**
**    A:   number of digits to convert.  Always "2" or "4".
**    B:   minimum value.  Always "0" or "1".
**    C:   maximum value, decoded as:
**           a:  12
**           b:  14
**           c:  24
**           d:  31
**           e:  59
**           f:  9999
**    D:   the separator character, or \000 to indicate this is the
**         last number to convert.
**
** Example:  To translate an ISO-8601 date YYYY-MM-DD, the format would

sqlite3.c  view on Meta::CPAN

  p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))];
  assert( pKeyInfo->aSortOrder!=0 );
  p->pKeyInfo = pKeyInfo;
  p->nField = pKeyInfo->nKeyField + 1;
  return p;
}

/*
** Given the nKey-byte encoding of a record in pKey[], populate the 
** UnpackedRecord structure indicated by the fourth argument with the
** contents of the decoded record.
*/ 
SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(
  KeyInfo *pKeyInfo,     /* Information about the record format */
  int nKey,              /* Size of the binary record */
  const void *pKey,      /* The binary record */
  UnpackedRecord *p      /* Populate this structure before returning. */
){
  const unsigned char *aKey = (const unsigned char *)pKey;
  int d; 
  u32 idx;                        /* Offset in aKey[] to read from */

sqlite3.c  view on Meta::CPAN

** skipped for length() and all content loading can be skipped for typeof().
*/
case OP_Column: {
  int p2;            /* column number to retrieve */
  VdbeCursor *pC;    /* The VDBE cursor */
  BtCursor *pCrsr;   /* The BTree cursor */
  u32 *aOffset;      /* aOffset[i] is offset to start of data for i-th column */
  int len;           /* The length of the serialized data for the column */
  int i;             /* Loop counter */
  Mem *pDest;        /* Where to write the extracted value */
  Mem sMem;          /* For storing the record being decoded */
  const u8 *zData;   /* Part of the record being decoded */
  const u8 *zHdr;    /* Next unparsed byte of the header */
  const u8 *zEndHdr; /* Pointer to first byte after the header */
  u64 offset64;      /* 64-bit offset */
  u32 t;             /* A type code from the record header */
  Mem *pReg;         /* PseudoTable input register */

  pC = p->apCsr[pOp->p1];
  p2 = pOp->p2;

  /* If the cursor cache is stale (meaning it is not currently point at

sqlite3.c  view on Meta::CPAN

}
#endif /* SQLITE_OMIT_VIRTUALTABLE */

#ifndef SQLITE_OMIT_VIRTUALTABLE
/* Opcode: VCreate P1 P2 * * *
**
** P2 is a register that holds the name of a virtual table in database 
** P1. Call the xCreate method for that table.
*/
case OP_VCreate: {
  Mem sMem;          /* For storing the record being decoded */
  const char *zTab;  /* Name of the virtual table */

  memset(&sMem, 0, sizeof(sMem));
  sMem.db = db;
  /* Because P2 is always a static string, it is impossible for the
  ** sqlite3VdbeMemCopy() to fail */
  assert( (aMem[pOp->p2].flags & MEM_Str)!=0 );
  assert( (aMem[pOp->p2].flags & MEM_Static)!=0 );
  rc = sqlite3VdbeMemCopy(&sMem, &aMem[pOp->p2]);
  assert( rc==SQLITE_OK );

sqlite3.c  view on Meta::CPAN

  /* If no test above fails then the indices must be compatible */
  return 1;
}

/*
** Attempt the transfer optimization on INSERTs of the form
**
**     INSERT INTO tab1 SELECT * FROM tab2;
**
** The xfer optimization transfers raw records from tab2 over to tab1.  
** Columns are not decoded and reassembled, which greatly improves
** performance.  Raw index records are transferred in the same way.
**
** The xfer optimization is only attempted if tab1 and tab2 are compatible.
** There are lots of rules for determining compatibility - see comments
** embedded in the code for details.
**
** This routine returns TRUE if the optimization is guaranteed to be used.
** Sometimes the xfer optimization will only work if the destination table
** is empty - a factor that can only be determined at run-time.  In that
** case, this routine generates code for the xfer optimization but also

sqlite3.c  view on Meta::CPAN

static int rtreeEof(sqlite3_vtab_cursor *cur){
  RtreeCursor *pCsr = (RtreeCursor *)cur;
  return pCsr->atEOF;
}

/*
** Convert raw bits from the on-disk RTree record into a coordinate value.
** The on-disk format is big-endian and needs to be converted for little-
** endian platforms.  The on-disk record stores integer coordinates if
** eInt is true and it stores 32-bit floating point records if eInt is
** false.  a[] is the four bytes of the on-disk record to be decoded.
** Store the results in "r".
**
** There are five versions of this macro.  The last one is generic.  The
** other four are various architectures-specific optimizations.
*/
#if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
#define RTREE_DECODE_COORD(eInt, a, r) {                        \
    RtreeCoord c;    /* Coordinate decoded */                   \
    c.u = _byteswap_ulong(*(u32*)a);                            \
    r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \
}
#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
#define RTREE_DECODE_COORD(eInt, a, r) {                        \
    RtreeCoord c;    /* Coordinate decoded */                   \
    c.u = __builtin_bswap32(*(u32*)a);                          \
    r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \
}
#elif SQLITE_BYTEORDER==1234
#define RTREE_DECODE_COORD(eInt, a, r) {                        \
    RtreeCoord c;    /* Coordinate decoded */                   \
    memcpy(&c.u,a,4);                                           \
    c.u = ((c.u>>24)&0xff)|((c.u>>8)&0xff00)|                   \
          ((c.u&0xff)<<24)|((c.u&0xff00)<<8);                   \
    r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \
}
#elif SQLITE_BYTEORDER==4321
#define RTREE_DECODE_COORD(eInt, a, r) {                        \
    RtreeCoord c;    /* Coordinate decoded */                   \
    memcpy(&c.u,a,4);                                           \
    r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \
}
#else
#define RTREE_DECODE_COORD(eInt, a, r) {                        \
    RtreeCoord c;    /* Coordinate decoded */                   \
    c.u = ((u32)a[0]<<24) + ((u32)a[1]<<16)                     \
           +((u32)a[2]<<8) + a[3];                              \
    r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \
}
#endif

/*
** Check the RTree node or entry given by pCellData and p against the MATCH
** constraint pConstraint.  
*/

sqlite3.c  view on Meta::CPAN

}

/*
** The implementation of user-defined scalar function fts5_decode().
*/
static void fts5DecodeFunction(
  sqlite3_context *pCtx,          /* Function call context */
  int nArg,                       /* Number of args (always 2) */
  sqlite3_value **apVal           /* Function arguments */
){
  i64 iRowid;                     /* Rowid for record being decoded */
  int iSegid,iHeight,iPgno,bDlidx;/* Rowid components */
  const u8 *aBlob; int n;         /* Record to decode */
  u8 *a = 0;
  Fts5Buffer s;                   /* Build up text to return here */
  int rc = SQLITE_OK;             /* Return code */
  int nSpace = 0;
  int eDetailNone = (sqlite3_user_data(pCtx)!=0);

  assert( nArg==2 );
  UNUSED_PARAM(nArg);

t/rt_78833_utf8_flag_for_column_names.t  view on Meta::CPAN

    my $tests = 27;
    plan( tests => $tests * 2 + 1 );
  } else {
    plan( skip_all => 'Unicode is not supported before 5.8.5' );
  }
}

use Test::NoWarnings;
use Encode;

unicode_test("\x{263A}");  # (decoded) smiley character
unicode_test("\x{0100}");  # (decoded) capital A with macron

sub unicode_test {
  my $unicode = shift;

  ok Encode::is_utf8($unicode), "correctly decoded";

  my $unicode_encoded = encode_utf8($unicode);

  { # tests for an environment where everything is encoded
    my $dbh = connect_ok(sqlite_unicode => 0);
    $dbh->do("pragma foreign_keys = on");
    my $unicode_quoted = $dbh->quote_identifier($unicode_encoded);
    $dbh->do("create table $unicode_quoted (id, $unicode_quoted primary key)");
    $dbh->do("create table bar (id, ref references $unicode_quoted ($unicode_encoded))");

t/rt_78833_utf8_flag_for_column_names.t  view on Meta::CPAN

      my ($id) = $dbh->selectrow_array("select id from $unicode_quoted where id = :$unicode_encoded", undef, 5);
      is $id => 5, "unicode placeholders";
    }

    {
      my $sth = $dbh->prepare("select * from $unicode_quoted where id = ?");
      $sth->execute(1);
      my $row = $sth->fetchrow_hashref;
      is $row->{id} => 1, "got correct row";
      is $row->{$unicode_encoded} => "text", "got correct (encoded) unicode column data";
      ok !exists $row->{$unicode}, "(decoded) unicode column does not exist";
    }

    {
      my $sth = $dbh->prepare("select $unicode_quoted from $unicode_quoted where id = ?");
      $sth->execute(1);
      my $row = $sth->fetchrow_hashref;
      is $row->{$unicode_encoded} => "text", "got correct (encoded) unicode column data";
      ok !exists $row->{$unicode}, "(decoded) unicode column does not exist";
    }

    {
      my $sth = $dbh->prepare("select id from $unicode_quoted where $unicode_quoted = ?");
      $sth->execute("text");
      my ($id) = $sth->fetchrow_array;
      is $id => 1, "got correct id by the (encoded) unicode column value";
    }

    {

t/rt_78833_utf8_flag_for_column_names.t  view on Meta::CPAN

      is $primary_key_info->{COLUMN_NAME} => $unicode_encoded, "primary_key_info returns the correctly encoded primary key name";
    }

    {
      my $sth = $dbh->table_info(undef, undef, $unicode_encoded);
      my $table_info = $sth->fetchrow_hashref;
      is $table_info->{TABLE_NAME} => $unicode_encoded, "table_info returns the correctly encoded table name";
    }
  }

  { # tests for an environment where everything is decoded
    my $dbh = connect_ok(sqlite_unicode => 1);
    $dbh->do("pragma foreign_keys = on");
    my $unicode_quoted = $dbh->quote_identifier($unicode);
    $dbh->do("create table $unicode_quoted (id, $unicode_quoted primary key)");
    $dbh->do("create table bar (id, ref references $unicode_quoted ($unicode_quoted))");

    ok $dbh->do("insert into $unicode_quoted values (?, ?)", undef, 1, "text"), "insert successfully";
    ok $dbh->do("insert into $unicode_quoted (id, $unicode_quoted) values (?, ?)", undef, 2, "text2"), "insert with unicode name successfully";

    {

t/rt_78833_utf8_flag_for_column_names.t  view on Meta::CPAN

      $sth->execute;
      my ($id) = $dbh->selectrow_array("select id from $unicode_quoted where id = :$unicode", undef, 5);
      is $id => 5, "unicode placeholders";
    }

    {
      my $sth = $dbh->prepare("select * from $unicode_quoted where id = ?");
      $sth->execute(1);
      my $row = $sth->fetchrow_hashref;
      is $row->{id} => 1, "got correct row";
      is $row->{$unicode} => "text", "got correct (decoded) unicode column data";
      ok !exists $row->{$unicode_encoded}, "(encoded) unicode column does not exist";
    }

    {
      my $sth = $dbh->prepare("select $unicode_quoted from $unicode_quoted where id = ?");
      $sth->execute(1);
      my $row = $sth->fetchrow_hashref;
      is $row->{$unicode} => "text", "got correct (decoded) unicode column data";
      ok !exists $row->{$unicode_encoded}, "(encoded) unicode column does not exist";
    }

    {
      my $sth = $dbh->prepare("select id from $unicode_quoted where $unicode_quoted = ?");
      $sth->execute("text2");
      my ($id) = $sth->fetchrow_array;
      is $id => 2, "got correct id by the (decoded) unicode column value";
    }

    {
      my $sth = $dbh->column_info(undef, undef, $unicode, $unicode);
      my $column_info = $sth->fetchrow_hashref;
      is $column_info->{COLUMN_NAME} => $unicode, "column_info returns the correctly decoded column name";
    }

    {
      my $sth = $dbh->primary_key_info(undef, undef, $unicode);
      my $primary_key_info = $sth->fetchrow_hashref;
      is $primary_key_info->{COLUMN_NAME} => $unicode, "primary_key_info returns the correctly decoded primary key name";
    }

    {
      my $sth = $dbh->table_info(undef, undef, $unicode);
      my $table_info = $sth->fetchrow_hashref;
      is $table_info->{TABLE_NAME} => $unicode, "table_info returns the correctly decoded table name";
    }
  }
}



( run in 0.327 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )