summaryrefslogtreecommitdiff
path: root/res
diff options
context:
space:
mode:
authorTilghman Lesher <tilghman@meg.abyt.es>2008-06-09 22:51:59 +0000
committerTilghman Lesher <tilghman@meg.abyt.es>2008-06-09 22:51:59 +0000
commit53459f86b2df0a2cd655a8c51dccd63073eacb87 (patch)
treea2740180dd4aac2db0c96b53467d9c9e329df7ff /res
parenta6a6821717ec5ad69188fe4f7a6a12d305c06295 (diff)
Expand RQ_INTEGER type out to multiple types, one for each precision
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@121367 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res')
-rw-r--r--res/res_config_curl.c11
-rw-r--r--res/res_config_odbc.c115
-rw-r--r--res/res_config_pgsql.c42
3 files changed, 128 insertions, 40 deletions
diff --git a/res/res_config_curl.c b/res/res_config_curl.c
index e0e1b0648..722b08e9d 100644
--- a/res/res_config_curl.c
+++ b/res/res_config_curl.c
@@ -430,7 +430,16 @@ static int require_curl(const char *url, const char *unused, va_list ap)
ast_uri_encode(elm, field, sizeof(field), EncodeSpecialChars);
ast_str_append(&query, 0, "%s=%s%%3A%d", field,
type == RQ_CHAR ? "char" :
- type == RQ_INTEGER ? "integer" :
+ type == RQ_INTEGER1 ? "integer1" :
+ type == RQ_UINTEGER1 ? "uinteger1" :
+ type == RQ_INTEGER2 ? "integer2" :
+ type == RQ_UINTEGER2 ? "uinteger2" :
+ type == RQ_INTEGER3 ? "integer3" :
+ type == RQ_UINTEGER3 ? "uinteger3" :
+ type == RQ_INTEGER4 ? "integer4" :
+ type == RQ_UINTEGER4 ? "uinteger4" :
+ type == RQ_INTEGER8 ? "integer8" :
+ type == RQ_UINTEGER8 ? "uinteger8" :
type == RQ_DATE ? "date" :
type == RQ_DATETIME ? "datetime" :
type == RQ_FLOAT ? "float" :
diff --git a/res/res_config_odbc.c b/res/res_config_odbc.c
index 9173cd706..4bd6f20d4 100644
--- a/res/res_config_odbc.c
+++ b/res/res_config_odbc.c
@@ -878,8 +878,8 @@ static struct ast_config *config_odbc(const char *database, const char *table, c
return cfg;
}
-#define warn_length(col, size) ast_log(LOG_WARNING, "Column %s is not long enough to contain realtime data (needs %d)\n", col->name, size)
-#define warn_type(col, type) ast_log(LOG_WARNING, "Column %s is of the incorrect type to contain realtime data\n", col->name)
+#define warn_length(col, size) ast_log(LOG_WARNING, "Realtime table %s@%s: column '%s' is not long enough to contain realtime data (needs %d)\n", table, database, col->name, size)
+#define warn_type(col, type) ast_log(LOG_WARNING, "Realtime table %s@%s: column '%s' is of the incorrect type (%d) to contain the required realtime data\n", table, database, col->name, col->type)
static int require_odbc(const char *database, const char *table, va_list ap)
{
@@ -907,15 +907,28 @@ static int require_odbc(const char *database, const char *table, va_list ap)
case SQL_VARBINARY:
case SQL_LONGVARBINARY:
case SQL_GUID:
- if ((type == RQ_INTEGER && size > 10) || (type == RQ_CHAR && col->size < size)) {
- warn_length(col, size);
- } else if (type == RQ_DATE && col->size < 10) {
- warn_length(col, 10);
- } else if (type == RQ_DATETIME && col->size < 19) {
- warn_length(col, 19);
- } else if (type == RQ_FLOAT && col->size < 10) {
- warn_length(col, 10);
+#define CHECK_SIZE(n) \
+ if (col->size < n) { \
+ warn_length(col, n); \
+ } \
+ break;
+ switch (type) {
+ case RQ_UINTEGER1: CHECK_SIZE(3) /* 255 */
+ case RQ_INTEGER1: CHECK_SIZE(4) /* -128 */
+ case RQ_UINTEGER2: CHECK_SIZE(5) /* 65535 */
+ case RQ_INTEGER2: CHECK_SIZE(6) /* -32768 */
+ case RQ_UINTEGER3: /* 16777215 */
+ case RQ_INTEGER3: CHECK_SIZE(8) /* -8388608 */
+ case RQ_DATE: /* 2008-06-09 */
+ case RQ_UINTEGER4: CHECK_SIZE(10) /* 4200000000 */
+ case RQ_INTEGER4: CHECK_SIZE(11) /* -2100000000 */
+ case RQ_DATETIME: /* 2008-06-09 16:03:47 */
+ case RQ_UINTEGER8: CHECK_SIZE(19) /* trust me */
+ case RQ_INTEGER8: CHECK_SIZE(20) /* ditto */
+ case RQ_FLOAT:
+ case RQ_CHAR: CHECK_SIZE(size)
}
+#undef CHECK_SIZE
break;
case SQL_TYPE_DATE:
if (type != RQ_DATE) {
@@ -928,44 +941,98 @@ static int require_odbc(const char *database, const char *table, va_list ap)
warn_type(col, type);
}
break;
- case SQL_INTEGER:
- case SQL_BIGINT:
- case SQL_SMALLINT:
- case SQL_TINYINT:
case SQL_BIT:
- if (type != RQ_INTEGER) {
- warn_type(col, type);
+ warn_length(col, size);
+ break;
+#define WARN_TYPE_OR_LENGTH(n) \
+ if (!ast_rq_is_int(type)) { \
+ warn_type(col, type); \
+ } else { \
+ warn_length(col, n); \
+ }
+ case SQL_TINYINT:
+ if (type != RQ_UINTEGER1) {
+ WARN_TYPE_OR_LENGTH(size)
+ }
+ break;
+ case SQL_C_STINYINT:
+ if (type != RQ_INTEGER1) {
+ WARN_TYPE_OR_LENGTH(size)
}
- if ((col->type == SQL_BIT && size > 1) ||
- (col->type == SQL_TINYINT && size > 2) ||
- (col->type == SQL_SMALLINT && size > 4) ||
- (col->type == SQL_INTEGER && size > 10)) {
- warn_length(col, size);
+ break;
+ case SQL_C_USHORT:
+ if (type != RQ_UINTEGER1 && type != RQ_INTEGER1 && type != RQ_UINTEGER2) {
+ WARN_TYPE_OR_LENGTH(size)
+ }
+ break;
+ case SQL_SMALLINT:
+ case SQL_C_SSHORT:
+ if (type != RQ_UINTEGER1 && type != RQ_INTEGER1 && type != RQ_INTEGER2) {
+ WARN_TYPE_OR_LENGTH(size)
+ }
+ break;
+ case SQL_C_ULONG:
+ if (type != RQ_UINTEGER1 && type != RQ_INTEGER1 &&
+ type != RQ_UINTEGER2 && type != RQ_INTEGER2 &&
+ type != RQ_UINTEGER3 && type != RQ_INTEGER3 &&
+ type != RQ_INTEGER4) {
+ WARN_TYPE_OR_LENGTH(size)
+ }
+ break;
+ case SQL_INTEGER:
+ case SQL_C_SLONG:
+ if (type != RQ_UINTEGER1 && type != RQ_INTEGER1 &&
+ type != RQ_UINTEGER2 && type != RQ_INTEGER2 &&
+ type != RQ_UINTEGER3 && type != RQ_INTEGER3 &&
+ type != RQ_UINTEGER4) {
+ WARN_TYPE_OR_LENGTH(size)
+ }
+ break;
+ case SQL_C_UBIGINT:
+ if (type != RQ_UINTEGER1 && type != RQ_INTEGER1 &&
+ type != RQ_UINTEGER2 && type != RQ_INTEGER2 &&
+ type != RQ_UINTEGER3 && type != RQ_INTEGER3 &&
+ type != RQ_UINTEGER4 && type != RQ_INTEGER4 &&
+ type != RQ_INTEGER8) {
+ WARN_TYPE_OR_LENGTH(size)
+ }
+ break;
+ case SQL_BIGINT:
+ case SQL_C_SBIGINT:
+ if (type != RQ_UINTEGER1 && type != RQ_INTEGER1 &&
+ type != RQ_UINTEGER2 && type != RQ_INTEGER2 &&
+ type != RQ_UINTEGER3 && type != RQ_INTEGER3 &&
+ type != RQ_UINTEGER4 && type != RQ_INTEGER4 &&
+ type != RQ_UINTEGER8) {
+ WARN_TYPE_OR_LENGTH(size)
}
break;
+#undef WARN_TYPE_OR_LENGTH
case SQL_NUMERIC:
case SQL_DECIMAL:
case SQL_FLOAT:
case SQL_REAL:
case SQL_DOUBLE:
- if (type != RQ_INTEGER && type != RQ_FLOAT) {
+ if (!ast_rq_is_int(type) && type != RQ_FLOAT) {
warn_type(col, type);
}
break;
default:
- ast_log(LOG_WARNING, "Column type (%d) unrecognized for field '%s' in %s@%s\n", col->type, elm, table, database);
+ ast_log(LOG_WARNING, "Realtime table %s@%s: column type (%d) unrecognized for column '%s'\n", table, database, col->type, elm);
}
break;
}
}
if (!col) {
- ast_log(LOG_WARNING, "Table %s@%s requires column '%s', but that column does not exist!\n", table, database, elm);
+ ast_log(LOG_WARNING, "Realtime table %s@%s requires column '%s', but that column does not exist!\n", table, database, elm);
}
}
va_end(ap);
AST_RWLIST_UNLOCK(&tableptr->columns);
return 0;
}
+#undef warn_length
+#undef warn_type
static int unload_odbc(const char *database, const char *tablename)
{
diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c
index 0afcf07e3..79c9c1937 100644
--- a/res/res_config_pgsql.c
+++ b/res/res_config_pgsql.c
@@ -943,14 +943,21 @@ static int require_pgsql(const char *database, const char *tablename, va_list ap
} else if (strncmp(column->type, "int", 3) == 0) {
int typesize = atoi(column->type + 3);
/* Integers can hold only other integers */
- if (type == RQ_INTEGER && ((typesize == 2 && size > 4) || (typesize == 4 && size > 10))) {
+ if ((type == RQ_INTEGER8 || type == RQ_UINTEGER8 ||
+ type == RQ_INTEGER4 || type == RQ_UINTEGER4 ||
+ type == RQ_INTEGER3 || type == RQ_UINTEGER3 ||
+ type == RQ_UINTEGER2) && typesize == 2) {
ast_log(LOG_WARNING, "Column '%s' may not be large enough for the required data length: %d\n", column->name, size);
res = -1;
- } else if (type != RQ_INTEGER) {
- ast_log(LOG_WARNING, "Column '%s' is of the incorrect type: (need %s(%d) but saw %s)\n", column->name, type == RQ_CHAR ? "char" : "something else ", size, column->type);
+ } else if ((type == RQ_INTEGER8 || type == RQ_UINTEGER8 ||
+ type == RQ_UINTEGER4) && typesize == 4) {
+ ast_log(LOG_WARNING, "Column '%s' may not be large enough for the required data length: %d\n", column->name, size);
+ res = -1;
+ } else if (type == RQ_CHAR || type == RQ_DATETIME || type == RQ_FLOAT || type == RQ_DATE) {
+ ast_log(LOG_WARNING, "Column '%s' is of the incorrect type: (need %s(%d) but saw %s)\n", column->name, type == RQ_CHAR ? "char" : type == RQ_DATETIME ? "datetime" : type == RQ_DATE ? "date" : type == RQ_FLOAT ? "float" : "a rather stiff drink ", size, column->type);
res = -1;
}
- } else if (strncmp(column->type, "float", 5) == 0 && type != RQ_INTEGER && type != RQ_FLOAT) {
+ } else if (strncmp(column->type, "float", 5) == 0 && !ast_rq_is_int(type) && type != RQ_FLOAT) {
ast_log(LOG_WARNING, "Column %s cannot be a %s\n", column->name, column->type);
res = -1;
} else { /* There are other types that no module implements yet */
@@ -965,25 +972,32 @@ static int require_pgsql(const char *database, const char *tablename, va_list ap
if (requirements == RQ_WARN) {
ast_log(LOG_WARNING, "Table %s requires a column '%s' of size '%d', but no such column exists.\n", tablename, elm, size);
} else {
- struct ast_str *sql = ast_str_create(100), *fieldtype = ast_str_create(16);
+ struct ast_str *sql = ast_str_create(100);
+ char fieldtype[15];
PGresult *res;
if (requirements == RQ_CREATECHAR || type == RQ_CHAR) {
- ast_str_set(&fieldtype, 0, "CHAR(%d)", size);
- } else if (type == RQ_INTEGER) {
- ast_str_set(&fieldtype, 0, "INT%d", size < 5 ? 2 : (size < 11 ? 4 : 8));
+ snprintf(fieldtype, sizeof(fieldtype), "CHAR(%d)", size);
+ } else if (type == RQ_INTEGER1 || type == RQ_UINTEGER1 || type == RQ_INTEGER2) {
+ snprintf(fieldtype, sizeof(fieldtype), "INT2");
+ } else if (type == RQ_UINTEGER2 || type == RQ_INTEGER3 || type == RQ_UINTEGER3 || type == RQ_INTEGER4) {
+ snprintf(fieldtype, sizeof(fieldtype), "INT4");
+ } else if (type == RQ_UINTEGER4 || type == RQ_INTEGER8) {
+ snprintf(fieldtype, sizeof(fieldtype), "INT8");
+ } else if (type == RQ_UINTEGER8) {
+ /* No such type on PostgreSQL */
+ snprintf(fieldtype, sizeof(fieldtype), "CHAR(20)");
} else if (type == RQ_FLOAT) {
- ast_str_set(&fieldtype, 0, "FLOAT8");
+ snprintf(fieldtype, sizeof(fieldtype), "FLOAT8");
} else if (type == RQ_DATE) {
- ast_str_set(&fieldtype, 0, "DATE");
+ snprintf(fieldtype, sizeof(fieldtype), "DATE");
} else if (type == RQ_DATETIME) {
- ast_str_set(&fieldtype, 0, "TIMESTAMP");
+ snprintf(fieldtype, sizeof(fieldtype), "TIMESTAMP");
} else {
ast_free(sql);
- ast_free(fieldtype);
continue;
}
- ast_str_set(&sql, 0, "ALTER TABLE %s ADD COLUMN %s %s", tablename, elm, fieldtype->str);
+ ast_str_set(&sql, 0, "ALTER TABLE %s ADD COLUMN %s %s", tablename, elm, fieldtype);
ast_debug(1, "About to lock pgsql_lock (running alter on table '%s' to add column '%s')\n", tablename, elm);
ast_mutex_lock(&pgsql_lock);
@@ -991,7 +1005,6 @@ static int require_pgsql(const char *database, const char *tablename, va_list ap
ast_mutex_unlock(&pgsql_lock);
ast_log(LOG_ERROR, "Unable to add column: %s\n", sql->str);
ast_free(sql);
- ast_free(fieldtype);
continue;
}
@@ -1005,7 +1018,6 @@ static int require_pgsql(const char *database, const char *tablename, va_list ap
ast_mutex_unlock(&pgsql_lock);
ast_free(sql);
- ast_free(fieldtype);
}
}
}