[libgda] GdaSqlParser: understand hexadecimal notation
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] GdaSqlParser: understand hexadecimal notation
- Date: Fri, 10 Aug 2012 19:25:39 +0000 (UTC)
commit e4bbbac4758220121aedef56dbbc3a8f53b61494
Author: Vivien Malerba <malerba gnome-db org>
Date: Fri Aug 10 21:20:44 2012 +0200
GdaSqlParser: understand hexadecimal notation
libgda/sql-parser/gda-sql-parser.c | 27 +++++++++++++++++----------
tests/parser/testdata.xml | 10 ++++++++++
2 files changed, 27 insertions(+), 10 deletions(-)
---
diff --git a/libgda/sql-parser/gda-sql-parser.c b/libgda/sql-parser/gda-sql-parser.c
index ab9fc46..c1a57bc 100644
--- a/libgda/sql-parser/gda-sql-parser.c
+++ b/libgda/sql-parser/gda-sql-parser.c
@@ -1296,17 +1296,24 @@ getToken (GdaSqlParser *parser)
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': {
parser->priv->context->token_type = L_INTEGER;
- for (i=0; isdigit (z[i]); i++){}
- if (z[i] == '.') {
- i++;
- while (isdigit (z[i])) {i++;}
- parser->priv->context->token_type = L_FLOAT;
+ if ((z[0] == '0') && ((z[1] == 'x') || (z[1] == 'X')) && (z[2] != 0)) {
+ /* hexadecimal */
+ for (i=2; isxdigit (z[i]); i++){}
}
- if ((z[i]=='e' || z[i]=='E') &&
- (isdigit (z[i+1]) || ((z[i+1]=='+' || z[i+1]=='-') && isdigit (z[i+2])))) {
- i += 2;
- while (isdigit (z[i])) {i++;}
- parser->priv->context->token_type = L_FLOAT;
+ else {
+ for (i=0; isdigit (z[i]); i++){}
+ if (z[i] == '.') {
+ i++;
+ while (isdigit (z[i])) {i++;}
+ parser->priv->context->token_type = L_FLOAT;
+ }
+ if ((z[i]=='e' || z[i]=='E') &&
+ (isdigit (z[i+1]) ||
+ ((z[i+1]=='+' || z[i+1]=='-') && isdigit (z[i+2])))) {
+ i += 2;
+ while (isdigit (z[i])) {i++;}
+ parser->priv->context->token_type = L_FLOAT;
+ }
}
if (parser->priv->mode != GDA_SQL_PARSER_MODE_DELIMIT) {
while (IdChar (z[i])) {
diff --git a/tests/parser/testdata.xml b/tests/parser/testdata.xml
index e414473..0a8fe00 100644
--- a/tests/parser/testdata.xml
+++ b/tests/parser/testdata.xml
@@ -74,6 +74,11 @@
<expected>{"statements":[{"statement":{"sql":"123","stmt_type":"UNKNOWN","contents":[{"value":"123"}]}}]}</expected>
</test>
+ <test id="11.1">
+ <sql>0xF0FB</sql>
+ <expected>{"statements":[{"statement":{"sql":"0xF0FB","stmt_type":"UNKNOWN","contents":[{"value":"0xF0FB"}]}}]}</expected>
+ </test>
+
<test id="12">
<sql>1.23</sql>
<expected>{"statements":[{"statement":{"sql":"1.23","stmt_type":"UNKNOWN","contents":[{"value":"1.23"}]}}]}</expected>
@@ -964,6 +969,11 @@
<expected>{"statements":[{"statement":{"sql":"select a not between 3 and 5","stmt_type":"SELECT","contents":{"distinct":"false","fields":[{"expr":{"operation":{"operator":"NOT","operand0":{"operation":{"operator":"BETWEEN","operand0":{"value":"a"},"operand1":{"value":"3"},"operand2":{"value":"5"}}}}}}]}}}]}</expected>
</test>
+ <test id="2248.1">
+ <sql>select a not between 0x056 and 0XFFA</sql>
+ <expected>{"statements":[{"statement":{"sql":"select a not between 0x056 and 0XFFA","stmt_type":"SELECT","contents":{"distinct":"false","fields":[{"expr":{"operation":{"operator":"NOT","operand0":{"operation":{"operator":"BETWEEN","operand0":{"value":"a"},"operand1":{"value":"0x056"},"operand2":{"value":"0XFFA"}}}}}}]}}}]}</expected>
+ </test>
+
<test id="2249">
<sql>select A union select B</sql>
<expected>{"statements":[{"statement":{"sql":"select A union select B","stmt_type":"COMPOUND","contents":{"compount_type":"UNION","select_stmts":[{"sql":null,"stmt_type":"SELECT","contents":{"distinct":"false","fields":[{"expr":{"value":"A"},"field_name":"A"}]}},{"sql":null,"stmt_type":"SELECT","contents":{"distinct":"false","fields":[{"expr":{"value":"B"},"field_name":"B"}]}}]}}}]}</expected>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]