64187cb8d0b32d1fdec9d90f326edf75750e185d kent Wed Mar 28 11:23:22 2012 -0700 First cut of Django output for autoSql. diff --git src/lib/asParse.c src/lib/asParse.c index 1286da4..af82459 100644 --- src/lib/asParse.c +++ src/lib/asParse.c @@ -1,47 +1,64 @@ /* asParse - parse out an autoSql .as file. */ #include "common.h" #include "linefile.h" #include "tokenizer.h" #include "dystring.h" #include "asParse.h" /* n.b. switched double/float from %f to %g to partially address losing * precision. Values like 2e-12 were being rounded to 0.0 with %f. While %g * doesn't match the precision of the database fields, specifying a larger * precision with %g resulted in numbers like 1.9999999999999999597733e-12, * which might impact load time. THis issue needs more investigation.*/ struct asTypeInfo asTypes[] = { - {t_double, "double", FALSE, FALSE, "double", "double", "Double", "Double", "%g"}, - {t_float, "float", FALSE, FALSE, "float", "float", "Float", "Float", "%g"}, - {t_char, "char", FALSE, FALSE, "char", "char", "Char", "Char", "%c"}, - {t_int, "int", FALSE, FALSE, "int", "int", "Signed", "Signed", "%d"}, - {t_uint, "uint", TRUE, FALSE, "int unsigned", "unsigned", "Unsigned","Unsigned", "%u"}, - {t_short, "short", FALSE, FALSE, "smallint", "short", "Short", "Signed", "%d"}, - {t_ushort, "ushort", TRUE, FALSE, "smallint unsigned","unsigned short","Ushort", "Unsigned", "%u"}, - {t_byte, "byte", FALSE, FALSE, "tinyint", "signed char", "Byte", "Signed", "%d"}, - {t_ubyte, "ubyte", TRUE, FALSE, "tinyint unsigned", "unsigned char", "Ubyte", "Unsigned", "%u"}, - {t_off, "bigint", FALSE, FALSE,"bigint", "long long", "LongLong", "LongLong", "%lld"}, - {t_string, "string", FALSE, TRUE, "varchar(255)", "char *", "String", "String", "%s"}, - {t_lstring, "lstring", FALSE, TRUE, "longblob", "char *", "String", "String", "%s"}, - {t_enum, "enum", FALSE, FALSE, "enum", "!error!", "Enum", "Enum", NULL}, - {t_set, "set", FALSE, FALSE, "set", "unsigned", "Set", "Set", NULL}, - {t_object, "object", FALSE, FALSE, "longblob", "!error!", "Object", "Object", NULL}, - {t_object, "table", FALSE, FALSE, "longblob", "!error!", "Object", "Object", NULL}, - {t_simple, "simple", FALSE, FALSE, "longblob", "!error!", "Simple", "Simple", NULL}, + {t_double, "double", FALSE, FALSE, "double", + "double", "Double", "Double", "%g", "FloatField"}, + {t_float, "float", FALSE, FALSE, "float", + "float", "Float", "Float", "%g", "FloatField"}, + {t_char, "char", FALSE, FALSE, "char", + "char", "Char", "Char", "%c", "CharField"}, + {t_int, "int", FALSE, FALSE, "int", + "int", "Signed", "Signed", "%d", "IntegerField"}, + {t_uint, "uint", TRUE, FALSE, "int unsigned", + "unsigned", "Unsigned","Unsigned", "%u", "PositiveIntegerField"}, + {t_short, "short", FALSE, FALSE, "smallint", + "short", "Short", "Signed", "%d", "SmallIntegerField"}, + {t_ushort, "ushort", TRUE, FALSE, "smallint unsigned", + "unsigned short","Ushort", "Unsigned", "%u", "SmallPositiveIntegerField"}, + {t_byte, "byte", FALSE, FALSE, "tinyint", + "signed char", "Byte", "Signed", "%d", "SmallIntegerField"}, + {t_ubyte, "ubyte", TRUE, FALSE, "tinyint unsigned", + "unsigned char", "Ubyte", "Unsigned", "%u", "SmallPositiveIntegerField"}, + {t_off, "bigint", FALSE, FALSE,"bigint", + "long long", "LongLong", "LongLong", "%lld", "BigIntegerField"}, + {t_string, "string", FALSE, TRUE, "varchar(255)", + "char *", "String", "String", "%s", "CharField"}, + {t_lstring, "lstring", FALSE, TRUE, "longblob", + "char *", "String", "String", "%s", "TextField"}, + {t_enum, "enum", FALSE, FALSE, "enum", + "!error!", "Enum", "Enum", NULL, "CharField"}, + {t_set, "set", FALSE, FALSE, "set", + "unsigned", "Set", "Set", NULL, NULL}, + {t_object, "object", FALSE, FALSE, "longblob", + "!error!", "Object", "Object", NULL, "TextField"}, + {t_object, "table", FALSE, FALSE, "longblob", + "!error!", "Object", "Object", NULL, "TextField"}, + {t_simple, "simple", FALSE, FALSE, "longblob", + "!error!", "Simple", "Simple", NULL, "TextField"}, }; static struct asTypeInfo *findLowType(struct tokenizer *tkz) /* Return low type info. Squawk and die if s doesn't * correspond to one. */ { char *s = tkz->string; int i; for (i=0; i<ArraySize(asTypes); ++i) { if (sameWord(asTypes[i].name, s)) return &asTypes[i]; } tokenizerErrAbort(tkz, "Unknown type '%s'", s); return NULL;