[patch] Support for utf8 in sql
Nirgal <[email protected]> Fri, 26 Aug 2011 08:19:34 +0000
| Newsgroups | gmane.comp.db.mdb-tools.devel |
|---|---|
| Message-ID | <[email protected]> |
Attached is a patch that fix utf8 usage in sql (flex) and makes a few cosmetic changes in mdb-sql ------------------------------------------------------------------------------ EMC VNX: the world's simplest storage, starting under $10K The only unified storage solution that offers unified management Up to 160% more powerful than alternatives and 25% more efficient. Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev _______________________________________________ mdbtools-dev mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mdbtools-dev
utfsql.diff
(text/x-patch, 2.7 KB)
Index: mdbtools-0.6pre1/src/sql/lexer.l
===================================================================
--- mdbtools-0.6pre1.orig/src/sql/lexer.l
+++ mdbtools-0.6pre1/src/sql/lexer.l
@@ -63,7 +63,7 @@
return IDENT;
}
-[A-Za-z][A-Za-z0-9_#@]* { yylval.name = strdup(yytext); return NAME; }
+[a-z\xa0-\xff][a-z0-9_#@\xa0-\xff]* { yylval.name = strdup(yytext); return NAME; }
'[^']*'' {
yyless(yyleng-1);
@@ -74,10 +74,13 @@
return STRING;
}
-(-*[0-9]+|([0-9]*\.[0-9]+)([eE][-+]?[0-9]+)?) {
- yylval.name = strdup(yytext); return NUMBER;
- }
-~?(\/?[A-Za-z0-9\.]+)+ { yylval.name = strdup(yytext); return PATH; }
+(-*[0-9]+|([0-9]*\.[0-9]+)(e[-+]?[0-9]+)?) {
+ yylval.name = strdup(yytext); return NUMBER;
+ }
+~?(\/?[a-z0-9\.\xa0-\xff]+)+ {
+ yylval.name = strdup(yytext); return PATH;
+ }
+
. { return yytext[0]; }
%%
Index: mdbtools-0.6pre1/configure.in
===================================================================
--- mdbtools-0.6pre1.orig/configure.in
+++ mdbtools-0.6pre1/configure.in
@@ -41,7 +41,7 @@
sql=true
AC_MSG_CHECKING( Are we using flex )
if test "x$LEX" = "xflex"; then
-LFLAGS="$LFLAGS -i"
+LFLAGS="$LFLAGS -i -8"
AC_MSG_RESULT( yes );
else
AC_MSG_RESULT( no - SQL engine disable);
Index: mdbtools-0.6pre1/src/sql/mdbsql.c
===================================================================
--- mdbtools-0.6pre1.orig/src/sql/mdbsql.c
+++ mdbtools-0.6pre1/src/sql/mdbsql.c
@@ -794,4 +794,3 @@
/* the column and table names are no good now */
mdb_sql_reset(sql);
}
-
Index: mdbtools-0.6pre1/src/util/mdb-sql.c
===================================================================
--- mdbtools-0.6pre1.orig/src/util/mdb-sql.c
+++ mdbtools-0.6pre1/src/util/mdb-sql.c
@@ -74,7 +74,7 @@
char *buf, line[1000];
int i = 0;
- printf("%s",prompt);
+ puts(prompt);
if (! fgets(line,1000,stdin)) {
return NULL;
}
@@ -91,6 +91,15 @@
}
#endif
+static int strlen_utf(const char *s) {
+ int len = 0;
+ while (*s) {
+ if ((*s++ & 0xc0) != 0x80)
+ len++;
+ }
+ return len;
+}
+
void
do_set_cmd(MdbSQL *sql, char *s)
{
@@ -215,25 +224,22 @@
int i;
int vlen;
- if (first) {
- fprintf(out,"|");
- }
- vlen = strlen(v);
- for (i=0;i<sz;i++) {
- fprintf(out,"%c",i >= vlen ? ' ' : v[i]);
- }
- fprintf(out,"|");
+ if (first)
+ fputc('|', out);
+ vlen = strlen_utf(v);
+ fputs(v, out);
+ for (i=vlen;i<sz;i++)
+ fputc(' ', out);
+ fputc('|', out);
}
static void print_break(FILE *out, int sz, int first)
{
int i;
- if (first) {
- fprintf(out,"+");
- }
- for (i=0;i<sz;i++) {
- fprintf(out,"-");
- }
- fprintf(out,"+");
+ if (first)
+ fputc('+', out);
+ for (i=0;i<sz;i++)
+ fputc('-', out);
+ fputc('+', out);
}
void print_rows_retrieved(FILE *out, unsigned long row_count)
{