Ejemplo n.º 1
0
Datum text_checksum2(PG_FUNCTION_ARGS)
{
  unsigned char * data;
  size_t size;
  if (PG_ARGISNULL(0))
  {
    data = NULL, size = 0;
  }
  else
  {
    text *t = PG_GETARG_TEXT_P(0);
    size = VARSIZE(t) - VARHDRSZ;
    data = (unsigned char *) VARDATA(t);
  }
  PG_RETURN_INT16(checksum_int2(data, size));
}
Ejemplo n.º 2
0
SQLITE_EXTENSION_INIT1
#else // not loadable
#include <sqlite3.h>
#endif // COMPILE_SQLITE_EXTENSIONS_AS_LOADABLE_MODULE

// plain C implementations
#include "jenkins.c"

/******************************************************* CHECKSUMS FUNCTIONS */

static void sqlite_checksum_int2(
  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_int(ctx, checksum_int2(txt, len));
}