Skip to content

Commit 0d8b656

Browse files
authored
Add VERSION type support (#312)
This adds support for the ES/SQL 'VERSION' type. The type is mapped to varchar.
1 parent 856ff9f commit 0d8b656

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

driver/connect.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#define TYPE_BOOLEAN "BOOLEAN"
5959
#define TYPE_INTEGER "INTEGER"
6060
#define TYPE_KEYWORD "KEYWORD"
61+
#define TYPE_VERSION "VERSION"
6162
/* 8 */
6263
#define TYPE_DATETIME "DATETIME"
6364
/* 9 */
@@ -2297,7 +2298,7 @@ static BOOL elastic_name2types(wstr_st *type_name,
22972298
}
22982299
break;
22992300

2300-
/* 7: INTEGER, BOOLEAN, KEYWORD */
2301+
/* 7: INTEGER, BOOLEAN, KEYWORD, VERSION */
23012302
case sizeof(TYPE_INTEGER) - 1:
23022303
switch (tolower(type_name->str[0])) {
23032304
case (SQLWCHAR)'i': /* integer */
@@ -2324,6 +2325,14 @@ static BOOL elastic_name2types(wstr_st *type_name,
23242325
return TRUE;
23252326
}
23262327
break;
2328+
case (SQLWCHAR)'v': /* version */
2329+
if (wmemncasecmp(type_name->str, MK_WPTR(TYPE_VERSION),
2330+
type_name->cnt) == 0) {
2331+
*c_sql = ES_VERSION_TO_CSQL;
2332+
*sql = ES_VERSION_TO_SQL;
2333+
return TRUE;
2334+
}
2335+
break;
23272336
}
23282337
break;
23292338

driver/defs.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@
417417
#define ESODBC_SQL_NESTED 2002
418418

419419
/* the SQL type ES/SQL uses for string types (KEYWORD, TEXT),
420-
* plus IP and GEO */
420+
* plus IP, VERSION and GEO */
421421
#define ESODBC_SQL_VARCHAR SQL_VARCHAR
422422

423423
/* C SQL and SQL types for ES types that
@@ -474,6 +474,9 @@
474474
/* 12: IP */
475475
#define ES_IP_TO_CSQL ES_VARCHAR_CSQL
476476
#define ES_IP_TO_SQL ES_VARCHAR_SQL
477+
/* 12: VERSION */
478+
#define ES_VERSION_TO_CSQL ES_VARCHAR_CSQL
479+
#define ES_VERSION_TO_SQL ES_VARCHAR_SQL
477480
/* 92: TIME */
478481
#define ES_TIME_TO_CSQL SQL_C_TYPE_TIME
479482
#define ES_TIME_TO_SQL SQL_TYPE_TIME

driver/queries.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,8 +2513,9 @@ esodbc_estype_st *lookup_es_type(esodbc_dbc_st *dbc,
25132513
SQLULEN i;
25142514
SQLINTEGER sz;
25152515

2516-
/* for strings, choose text straight away: some type (IP, GEO) must coform
2517-
* to a format and no content inspection is done in the driver */
2516+
/* for strings, choose text straight away: some types (IP, VERSION, GEO)
2517+
* must conform to a format and no content inspection is done in the driver
2518+
*/
25182519
if (es_type == ES_VARCHAR_SQL || es_type == ES_WVARCHAR_SQL) {
25192520
return dbc->max_varchar_type;
25202521
}
@@ -2554,7 +2555,7 @@ static esodbc_estype_st *match_es_type(esodbc_rec_st *irec)
25542555
return dbc->max_float_type;
25552556
break;
25562557
case ES_WVARCHAR_SQL: /* KEYWORD, TEXT */
2557-
case ES_VARCHAR_SQL: /* IP, GEO+ */
2558+
case ES_VARCHAR_SQL: /* IP, VERSION, GEO+ */
25582559
return dbc->max_varchar_type;
25592560
default:
25602561
/* unequivocal match */
@@ -2877,7 +2878,7 @@ static SQLRETURN convert_param_val(esodbc_rec_st *arec, esodbc_rec_st *irec,
28772878

28782879
/* JSON string */
28792880
case ES_WVARCHAR_SQL: /* KEYWORD, TEXT */
2880-
case ES_VARCHAR_SQL: /* IP, GEO+ */
2881+
case ES_VARCHAR_SQL: /* IP, VERSION, GEO+ */
28812882
return c2sql_varchar(arec, irec, pos, dest, len);
28822883

28832884
case SQL_TYPE_DATE:

test/connected_dbc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ extern "C" {
7777
[\"IP\", 12, 45, \"'\", \"'\", null, 2, false, 3, true, false, false, null, null, null, 12, 0, null, null],\
7878
[\"KEYWORD\", 12, 32766, \"'\", \"'\", null, 2, true, 3, true, false, false, null, null, null, 12, 0, null, null],\
7979
[\"TEXT\", 12, 2147483647, \"'\", \"'\", null, 2, true, 3, true, false, false, null, null, null, 12, 0, null, null],\
80+
[\"VERSION\", 12, 2147483647, \"'\", \"'\", null, 2, true, 3, true, false, false, null, null, null, 12, 0, null, null],\
8081
[\"BOOLEAN\", 16, 1, \"'\", \"'\", null, 2, false, 3, true, false, false, null, null, null, 16, 0, null, null],\
8182
[\"DATE\", 91, 29, \"'\", \"'\", null, 2, false, 3, true, false, false, null, 3, 3, 91, 0, null, null],\
8283
[\"TIME\", 92, 18, \"'\", \"'\", null, 2, false, 3, true, false, false, null, null, null, 92, 0, null, null],\

test/integration/elasticsearch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def _update_es_yaml(self, es_dir, append=True):
152152
with open(yaml, mode="a" if append else "w", newline="\n") as f:
153153
f.write("#\n# ODBC Integration Test\n#\n")
154154
f.write("xpack.security.enabled: True\n")
155+
f.write("xpack.watcher.enabled: False\n")
155156
f.write("http.port: %s\n" % self._port) # don't bind on next avail port
156157
f.write("cluster.routing.allocation.disk.threshold_enabled: False\n")
157158

0 commit comments

Comments
 (0)