I am trying to call a C function in a sqlite 2 trigger.

Here is the code
'''''''''''''''''''''''''''''''''''''''

#include <stdio.h>
#include <sqlite.h>
#include <assert.h>



void capitalize_alternate(sqlite_func *context, int argc, const char **argv)
{
  int i;
  static char str[80];

  for (i=0; i<strlen(argv[0]); i++) {
    if (i%2 == 0)
      str[i] = toupper(argv[0][i]);
    else
      str[i] = tolower(argv[0][i]);
  }
  str[i] = '\0';
  sqlite_set_result_string(context, str, -1);
}

int main()
{

  char *errmsg;
  char **result;
  char str[80];
  int ret, rows, cols, i, j;

  sqlite *db = sqlite_open("/home/test", 0777, &errmsg);

  if (db == 0)
  {
    fprintf(stderr, "Could not open database: %s\n", errmsg);
    sqlite_freemem(errmsg);
    exit(1);
  }

 sqlite_create_function(db, "altcaps", 1, capitalize_alternate, NULL);

ret = sqlite_exec(db,
          " CREATE TRIGGER example   \n"
          "  AFTER INSERT ON contacts \n"
          "  BEGIN        \n"
          "  SELECT altcaps('this is a test');      \n"
          "  END",  NULL, NULL, &errmsg);
  if (ret != SQLITE_OK)
  {
    fprintf(stderr, "SQL Error: %s\n", errmsg);
  }
  sqlite_close(db);
return 0;
}

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
when I complile the progrm with gcc

 gcc -Wall firsttprog.c -o firstprog -lsqlite

./firstprog


It compiles without error and it creates the trigger "example"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
sqlite> select * from sqlite_master;

table|contacts|contacts|3|create table contacts (int a)
table|requests|requests|4|create table requests(a int)

trigger|example|contacts|0|CREATE TRIGGER example
  AFTER INSERT ON contacts
  BEGIN
  SELECT altcaps('this is a test');
  END

sqlite>insert into contacts values(2);
SQL error: no such function: altcaps
sqlite>
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Here it says no such function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Could anyone help me with that please.

Regards,

Nick
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to