[SR-Users] [PATCH] modules_k/db_sqlite: make decltype matching case-insensitive
Daniel-Constantin Mierla
miconda at gmail.com
Tue May 22 10:46:34 CEST 2012
Hello,
On 5/19/12 10:39 PM, Timo Teräs wrote:
> Search for keywords case insensitively instead of using strstr().
> SQlite stores decltype as-is, and does the affinity type testing
> case insensitively too.
Perhaps you should push it asap, so it gets some testing before 3.3.0 is
released.
Thanks,
Daniel
> ---
> modules_k/db_sqlite/dbase.c | 53 +++++++++++++++++++++++++++++--------------
> 1 file changed, 36 insertions(+), 17 deletions(-)
>
> I'm testing currently this patch. Unless something comes up, I will push
> this shortly.
>
> diff --git a/modules_k/db_sqlite/dbase.c b/modules_k/db_sqlite/dbase.c
> index 67db13b..f69192a 100644
> --- a/modules_k/db_sqlite/dbase.c
> +++ b/modules_k/db_sqlite/dbase.c
> @@ -237,28 +237,47 @@ static int db_sqlite_submit_query(const db1_con_t* _h, const str* _s)
> return 0;
> }
>
> +#define H3(a,b,c) ((a<<16) + (b<<8) + c)
> +#define H4(a,b,c,d) ((a<<24) + (b<<16) + (c<<8) + d)
> +
> static int decltype_to_dbtype(const char *decltype)
> {
> /* SQlite3 has dynamic typing. It does not store the actual
> * exact type, instead it uses 'affinity' depending on the
> * value. We have to go through the declaration types to see
> - * what to return. */
> - if (strstr(decltype, "INT") != NULL ||
> - strncasecmp(decltype, "SERIAL", 6) == 0)
> - return DB1_INT;
> - if (strstr(decltype, "CHAR") != NULL)
> - return DB1_STRING;
> - if (strstr(decltype, "TEXT") != NULL)
> - return DB1_STR;
> - if (strstr(decltype, "REAL") != NULL ||
> - strstr(decltype, "FLOA") != NULL ||
> - strstr(decltype, "DOUB") != NULL)
> - return DB1_DOUBLE;
> - if (strstr(decltype, "BLOB") != NULL)
> - return DB1_BLOB;
> - if (strncasecmp(decltype, "TIME", 4) == 0 ||
> - strncasecmp(decltype, "DATE", 4) == 0)
> - return DB1_DATETIME;
> + * what to return. This differs from SQlite affinity type, as
> + * we want to match with srdb type. */
> +
> + uint32_t h = 0;
> +
> + for (; *decltype; decltype++) {
> + h <<= 8;
> + h += toupper(*decltype);
> +
> + switch (h & 0x00ffffff) {
> + case H3('I','N','T'):
> + return DB1_INT;
> + }
> +
> + switch (h) {
> + case H4('S','E','R','I'): /* SERIAL */
> + return DB1_INT;
> + case H4('C','H','A','R'):
> + return DB1_STRING;
> + case H4('T','E','X','T'):
> + return DB1_STR;
> + case H4('R','E','A','L'):
> + case H4('F','L','O','A'):
> + case H4('D','O','U','B'):
> + return DB1_DOUBLE;
> + case H4('B','L','O','B'):
> + case H4('B','Y','T','E'):
> + return DB1_BLOB;
> + case H4('T','I','M','E'):
> + case H4('D','A','T','E'):
> + return DB1_DATETIME;
> + }
> + }
>
> LM_ERR("sqlite decltype '%s' not recognized, defaulting to int",
> decltype);
--
Daniel-Constantin Mierla - http://www.asipto.com
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
More information about the sr-users
mailing list