chiark / gitweb /
Treat integers as integers. (Not ideal, and we may need to revisit this later and...
authorThomas Thurman <tthurman@gnome.org>
Sat, 16 Oct 2010 18:40:12 +0000 (14:40 -0400)
committerThomas Thurman <tthurman@gnome.org>
Sat, 16 Oct 2010 18:40:12 +0000 (14:40 -0400)
breviary/breviary-build-db.c

index ce058cc..922a519 100644 (file)
@@ -57,18 +57,41 @@ submit (LoadIntoDatabaseContext *context)
 
   for (i=0; i<context->fields; i++)
     {
+      int is_number = 0;
+      char *value = context->values[i];
+
       printf ("Value %d: %s\n",
              i+1,
-             context->values[i]);
-
-      /*
-       FIXME: This needs to use sqlite3_bind_int
-       IF the field is entirely digits
-      */
-      sqlite3_bind_text (context->statement,
-                        i+1,
-                        context->values[i],
-                        -1, NULL);
+             value);
+
+      if (value && value[0])
+       {
+         char *cursor = value;
+         while (*cursor>='0' &&
+                *cursor<='9')
+           {
+             cursor++;
+           }
+
+         if (*cursor==0)
+           {
+             is_number = 1;
+           }
+       }
+
+      if (is_number)
+       {
+         sqlite3_bind_int (context->statement,
+                           i+1,
+                           atoi (value));
+       }
+      else
+       {
+         sqlite3_bind_text (context->statement,
+                            i+1,
+                            context->values[i],
+                            -1, NULL);
+       }
     }
 
   sqlite3_step (context->statement);