Changeset: c52392e28ecc for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c52392e28ecc Modified Files: sql/server/sql_mvc.c Branch: sciql Log Message:
Merge with default branch. diffs (truncated from 1864 to 300 lines): diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c --- a/clients/mapilib/mapi.c +++ b/clients/mapilib/mapi.c @@ -846,6 +846,8 @@ struct MapiColumn { char *columnname; char *columntype; int columnlength; + int digits; + int scale; }; /* information about bound columns */ @@ -3498,6 +3500,19 @@ mapi_setAutocommit(Mapi mid, int autocom } MapiMsg +mapi_set_size_header(Mapi mid, int value) +{ + if (mid->languageId != LANG_SQL) { + mapi_setError(mid, "size header only supported in SQL", "mapi_toggle_size_header", MERROR); + return MERROR; + } + if (value) + return mapi_Xcommand(mid, "sizeheader", "1"); + else + return mapi_Xcommand(mid, "sizeheader", "0"); +} + +MapiMsg mapi_trace(Mapi mid, int flag) { mapi_clrError(mid); @@ -3804,6 +3819,16 @@ parse_header_line(MapiHdl hdl, char *lin anchors[i] = NULL; } } + } else if (strcmp(tag, "typesizes") == 0) { + for (i = 0; i < n; i++) { + if (anchors[i]) { + char *p; + result->fields[i].digits = atoi(anchors[i]); + p = strchr(anchors[i], ' '); + if (p) + result->fields[i].scale = atoi(p + 1); + } + } } /* clean up */ @@ -5267,6 +5292,30 @@ mapi_get_len(MapiHdl hdl, int fnr) return 0; } +int +mapi_get_digits(MapiHdl hdl, int fnr) +{ + struct MapiResultSet *result; + + mapi_hdl_check0(hdl, "mapi_get_digits"); + if ((result = hdl->result) != 0 && fnr >= 0 && fnr < result->fieldcnt) + return result->fields[fnr].digits; + mapi_setError(hdl->mid, "Illegal field number", "mapi_get_digits", MERROR); + return 0; +} + +int +mapi_get_scale(MapiHdl hdl, int fnr) +{ + struct MapiResultSet *result; + + mapi_hdl_check0(hdl, "mapi_get_scale"); + if ((result = hdl->result) != 0 && fnr >= 0 && fnr < result->fieldcnt) + return result->fields[fnr].scale; + mapi_setError(hdl->mid, "Illegal field number", "mapi_get_scale", MERROR); + return 0; +} + char * mapi_get_query(MapiHdl hdl) { diff --git a/clients/mapilib/mapi.h b/clients/mapilib/mapi.h --- a/clients/mapilib/mapi.h +++ b/clients/mapilib/mapi.h @@ -165,6 +165,7 @@ mapi_export int mapi_get_trace(Mapi mid) mapi_export int mapi_get_autocommit(Mapi mid); mapi_export MapiMsg mapi_log(Mapi mid, const char *nme); mapi_export MapiMsg mapi_setAutocommit(Mapi mid, int autocommit); +mapi_export MapiMsg mapi_set_size_header(Mapi mid, int value); mapi_export char *mapi_result_error(MapiHdl hdl); mapi_export MapiMsg mapi_next_result(MapiHdl hdl); mapi_export MapiMsg mapi_needmore(MapiHdl hdl); @@ -232,6 +233,8 @@ mapi_export char *mapi_get_table(MapiHdl mapi_export char *mapi_get_name(MapiHdl hdl, int fnr); mapi_export char *mapi_get_type(MapiHdl hdl, int fnr); mapi_export int mapi_get_len(MapiHdl hdl, int fnr); +mapi_export int mapi_get_digits(MapiHdl hdl, int fnr); +mapi_export int mapi_get_scale(MapiHdl hdl, int fnr); mapi_export char *mapi_get_query(MapiHdl hdl); mapi_export int mapi_get_querytype(MapiHdl hdl); mapi_export int mapi_get_tableid(MapiHdl hdl); diff --git a/clients/odbc/driver/ODBCConvert.c b/clients/odbc/driver/ODBCConvert.c --- a/clients/odbc/driver/ODBCConvert.c +++ b/clients/odbc/driver/ODBCConvert.c @@ -44,7 +44,7 @@ # define O_ULLCAST (unsigned __int64) #endif -#define MAXBIGNUM10 ULL_CONSTANT(1844674407370955161) /* (2**64-1)/10 */ +#define MAXBIGNUM10 ULL_CONSTANT(1844674407370955161) /* (2**64-1)/10 */ #define MAXBIGNUMLAST '5' /* (2**64-1)%10 */ #define space(c) ((c) == ' ' || (c) == '\t') @@ -52,9 +52,9 @@ typedef struct { unsigned char precision; /* total number of digits */ signed char scale; /* how far to shift decimal point (> - 0: shift left, i.e. number has - fraction; < 0: shift right, - i.e. multiply with power of 10) */ + * 0: shift left, i.e. number has + * fraction; < 0: shift right, + * i.e. multiply with power of 10) */ unsigned char sign; /* 1 pos, 0 neg */ SQLUBIGINT val; /* the value */ } bignum_t; @@ -81,9 +81,9 @@ strncasecmp(const char *s1, const char * #endif /* Parse a number and store in a bignum_t. - 1 is returned if all is well; - 2 is returned if there is loss of precision (i.e. overflow of the value); - 0 is returned if the string is not a number, or if scale doesn't fit. + * 1 is returned if all is well; + * 2 is returned if there is loss of precision (i.e. overflow of the value); + * 0 is returned if the string is not a number, or if scale doesn't fit. */ static int parseint(const char *data, bignum_t *nval) @@ -109,7 +109,10 @@ parseint(const char *data, bignum_t *nva if (*data == '.') fraction = 1; else if ('0' <= *data && *data <= '9') { - if (overflow || nval->val > MAXBIGNUM10 || (nval->val == MAXBIGNUM10 && *data > MAXBIGNUMLAST)) { + if (overflow || + nval->val > MAXBIGNUM10 || + (nval->val == MAXBIGNUM10 && + *data > MAXBIGNUMLAST)) { overflow = 1; if (!fraction) scale--; @@ -258,8 +261,10 @@ parsedate(const char *data, DATE_STRUCT while (space(*data)) data++; - if (sscanf(data, "{d '%hd-%hu-%hu'}%n", &dval->year, &dval->month, &dval->day, &n) < 3 && - sscanf(data, "%hd-%hu-%hu%n", &dval->year, &dval->month, &dval->day, &n) < 3) + if (sscanf(data, "{d '%hd-%hu-%hu'}%n", + &dval->year, &dval->month, &dval->day, &n) < 3 && + sscanf(data, "%hd-%hu-%hu%n", + &dval->year, &dval->month, &dval->day, &n) < 3) return 0; if (dval->month == 0 || dval->month > 12 || dval->day == 0 || dval->day > monthlengths[dval->month] || @@ -281,8 +286,10 @@ parsetime(const char *data, TIME_STRUCT while (space(*data)) data++; - if (sscanf(data, "{t '%hu:%hu:%hu%n", &tval->hour, &tval->minute, &tval->second, &n) < 3 && - sscanf(data, "%hu:%hu:%hu%n", &tval->hour, &tval->minute, &tval->second, &n) < 3) + if (sscanf(data, "{t '%hu:%hu:%hu%n", + &tval->hour, &tval->minute, &tval->second, &n) < 3 && + sscanf(data, "%hu:%hu:%hu%n", + &tval->hour, &tval->minute, &tval->second, &n) < 3) return 0; /* seconds can go up to 61(!) because of leap seconds */ if (tval->hour > 23 || tval->minute > 59 || tval->second > 61) @@ -295,6 +302,18 @@ parsetime(const char *data, TIME_STRUCT ; n = 2; /* indicate loss of precision */ } + if (*data == '+' || *data == '-') { + /* time zone (which we ignore) */ + short tzhour, tzmin; + int i; + + if (sscanf(data, "%hd:%hd%n", &tzhour, &tzmin, &i) < 2) + return 0; + data += i; + tzmin = tzhour < 0 ? tzhour * 60 - tzmin : tzhour * 60 + tzmin; + (void) tzhour; + (void) tzmin; + } if (braces && *data++ != '\'' && *data++ != '}') return 0; while (space(*data)) @@ -312,8 +331,12 @@ parsetimestamp(const char *data, TIMESTA while (space(*data)) data++; - if (sscanf(data, "{TS '%hd-%hu-%hu %hu:%hu:%hu%n", &tsval->year, &tsval->month, &tsval->day, &tsval->hour, &tsval->minute, &tsval->second, &n) < 6 && - sscanf(data, "%hd-%hu-%hu %hu:%hu:%hu%n", &tsval->year, &tsval->month, &tsval->day, &tsval->hour, &tsval->minute, &tsval->second, &n) < 6) + if (sscanf(data, "{TS '%hd-%hu-%hu %hu:%hu:%hu%n", + &tsval->year, &tsval->month, &tsval->day, + &tsval->hour, &tsval->minute, &tsval->second, &n) < 6 && + sscanf(data, "%hd-%hu-%hu %hu:%hu:%hu%n", + &tsval->year, &tsval->month, &tsval->day, + &tsval->hour, &tsval->minute, &tsval->second, &n) < 6) return 0; if (tsval->month == 0 || tsval->month > 12 || tsval->day == 0 || tsval->day > monthlengths[tsval->month] || @@ -330,6 +353,18 @@ parsetimestamp(const char *data, TIMESTA tsval->fraction += (*data - '0') * n; } } + if (*data == '+' || *data == '-') { + /* time zone (which we ignore) */ + short tzhour, tzmin; + int i; + + if (sscanf(data, "%hd:%hd%n", &tzhour, &tzmin, &i) < 2) + return 0; + data += i; + tzmin = tzhour < 0 ? tzhour * 60 - tzmin : tzhour * 60 + tzmin; + (void) tzhour; + (void) tzmin; + } if (braces && *data++ != '\'' && *data++ != '}') return 0; while (space(*data)) @@ -458,7 +493,7 @@ parseoptionalbracketednumber(char **sval sval++; } /* make sure there is a closing parenthesis in the string: - this makes the calls to strtol safe */ + * this makes the calls to strtol safe */ { SQLLEN i; @@ -537,7 +572,7 @@ parsemonthintervalstring(char **svalp, slen--; sval++; /* make sure there is another quote in the string: this makes - the calls to strtol safe */ + * the calls to strtol safe */ for (eptr = sval, leadingprecision = slen; leadingprecision > 0 && *eptr != '\''; leadingprecision--, eptr++) @@ -694,7 +729,7 @@ parsesecondintervalstring(char **svalp, slen--; sval++; /* make sure there is another quote in the string: this makes - the calls to sscanf safe */ + * the calls to sscanf safe */ for (eptr = sval, leadingprecision = slen; leadingprecision > 0 && *eptr != '\''; leadingprecision--, eptr++) @@ -704,8 +739,8 @@ parsesecondintervalstring(char **svalp, if (*sval == '+' || *sval == '-') return SQL_ERROR; /* note that the first bit is a bogus comparison (sval does - not start with '-', so is not negative) but this keeps the - compiler happy */ + * not start with '-', so is not negative) but this keeps the + * compiler happy */ if (strtol(sval, &eptr, 10) < 0 || /* we parse the actual value again later */ eptr == sval) return SQL_ERROR; @@ -1007,9 +1042,9 @@ ODBCFetch(ODBCStmt *stmt, /* translate default type */ /* note, type can't be SQL_ARD_TYPE since when this function - is called from SQLFetch, type is already the ARD concise - type, and when it is called from SQLGetData, it has already - been translated */ + * is called from SQLFetch, type is already the ARD concise + * type, and when it is called from SQLGetData, it has already + * been translated */ if (type == SQL_C_DEFAULT) type = ODBCDefaultType(irdrec); @@ -1071,15 +1106,15 @@ ODBCFetch(ODBCStmt *stmt, case SQL_INTERVAL_SECOND: if (!parseint(data, &nval)) { /* shouldn't happen: getting here means SQL - server told us a value was of a certain - type, but in reality it wasn't. */ + * server told us a value was of a certain + * type, but in reality it wasn't. */ /* Invalid character value for cast specification */ addStmtError(stmt, "22018", NULL, 0); return SQL_ERROR; } /* interval types are transferred as ints but need to - be converted to the internal interval formats */ + * be converted to the internal interval formats */ if (sql_type == SQL_INTERVAL_SECOND) ivalprec = parsesecondinterval(&nval, &ival, sql_type); else if (sql_type == SQL_INTERVAL_MONTH) @@ -1293,7 +1328,7 @@ ODBCFetch(ODBCStmt *stmt, _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list