[svn-commits] tilghman: trunk r641 - /trunk/res/res_config_mysql.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jun 9 20:03:09 CDT 2008


Author: tilghman
Date: Mon Jun  9 20:03:08 2008
New Revision: 641

URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=641
Log:
Update to recent addition of more specific integer type fields

Modified:
    trunk/res/res_config_mysql.c

Modified: trunk/res/res_config_mysql.c
URL: http://svn.digium.com/view/asterisk-addons/trunk/res/res_config_mysql.c?view=diff&rev=641&r1=640&r2=641
==============================================================================
--- trunk/res/res_config_mysql.c (original)
+++ trunk/res/res_config_mysql.c Mon Jun  9 20:03:08 2008
@@ -178,8 +178,7 @@
 			}
 
 			if ((flen = strchr(ftype, '('))) {
-				*flen++ = '\0';
-				sscanf(flen, "%d", &column->len);
+				sscanf(flen, "(%d)", &column->len);
 			} else {
 				/* Columns like dates, times, and timestamps don't have a length */
 				column->len = -1;
@@ -831,27 +830,92 @@
 		AST_LIST_TRAVERSE(&table->columns, column, list) {
 			if (strcmp(column->name, elm) == 0) {
 				/* Char can hold anything, as long as it is large enough */
-				if ((strncmp(column->type, "char", 4) == 0 || strncmp(column->type, "varchar", 7) == 0 || strcmp(column->type, "bpchar") == 0)) {
+				if (strncmp(column->type, "char", 4) == 0 || strncmp(column->type, "varchar", 7) == 0) {
 					if ((size > column->len) && column->len != -1) {
 						ast_log(LOG_WARNING, "Column '%s' should be at least %d long, but is only %d long.\n", column->name, size, column->len);
 						res = -1;
 					}
+				} else if (strcasestr(column->type, "unsigned")) {
+					if (!ast_rq_is_int(type)) {
+						ast_log(LOG_WARNING, "Realtime table %s@%s: column '%s' cannot be type '%s' (need %s)\n", database, tablename, column->name, column->type,
+							type == RQ_CHAR ? "char" : type == RQ_FLOAT ? "float" : type == RQ_DATETIME ? "datetime" : type == RQ_DATE ? "date" : "a rather stiff drink");
+						res = -1;
+					} else if (strncasecmp(column->type, "tinyint", 1) == 0) {
+						if (type != RQ_UINTEGER1) {
+							ast_log(LOG_WARNING, "Realtime table %s@%s: column '%s' may not be large enough for the required data length: %d (detected unsigned tinyint)\n", tablename, database, column->name, size);
+							res = -1;
+						}
+					} else if (strncasecmp(column->type, "smallint", 1) == 0) {
+						if (type != RQ_UINTEGER1 && type != RQ_INTEGER1 && type != RQ_UINTEGER2) {
+							ast_log(LOG_WARNING, "Realtime table %s@%s: column '%s' may not be large enough for the required data length: %d (detected unsigned smallint)\n", tablename, database, column->name, size);
+							res = -1;
+						}
+					} else if (strncasecmp(column->type, "mediumint", 1) == 0) {
+						if (type != RQ_UINTEGER1 && type != RQ_INTEGER1 &&
+							type != RQ_UINTEGER2 && type != RQ_INTEGER2 &&
+							type != RQ_UINTEGER3) {
+							ast_log(LOG_WARNING, "Realtime table %s@%s: column '%s' may not be large enough for the required data length: %d (detected unsigned mediumint)\n", tablename, database, column->name, size);
+							res = -1;
+						}
+					} else if (strncasecmp(column->type, "int", 1) == 0) {
+						if (type != RQ_UINTEGER1 && type != RQ_INTEGER1 &&
+							type != RQ_UINTEGER2 && type != RQ_INTEGER2 &&
+							type != RQ_UINTEGER3 && type != RQ_INTEGER3 &&
+							type != RQ_UINTEGER4) {
+							ast_log(LOG_WARNING, "Realtime table %s@%s: column '%s' may not be large enough for the required data length: %d (detected unsigned int)\n", tablename, database, column->name, size);
+							res = -1;
+						}
+					} else if (strncasecmp(column->type, "bigint", 1) == 0) {
+						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) {
+							ast_log(LOG_WARNING, "Realtime table %s@%s: column '%s' may not be large enough for the required data length: %d (detected unsigned bigint)\n", tablename, database, column->name, size);
+							res = -1;
+						}
+					}
 				} else if (strcasestr(column->type, "int")) {
-					int typesize = (
-						!strncasecmp(column->type, "tiny", 1) ? 3 :
-						!strncasecmp(column->type, "small", 1) ? 5 :
-						!strncasecmp(column->type, "medium", 1) ? 8 :
-						!strncasecmp(column->type, "int", 1) ? 11 :
-						23); /* bigint */
-					/* Integers can hold only other integers */
-					if (type == RQ_INTEGER && (typesize < size)) {
-						ast_log(LOG_WARNING, "Column '%s' may not be large enough for the required data length: %d (detected only %d)\n", column->name, size, typesize);
+					if (!ast_rq_is_int(type)) {
+						ast_log(LOG_WARNING, "Realtime table %s@%s: column '%s' cannot be type '%s' (need %s)\n", database, tablename, column->name, column->type,
+							type == RQ_CHAR ? "char" : type == RQ_FLOAT ? "float" : type == RQ_DATETIME ? "datetime" : type == RQ_DATE ? "date" : "to get a life, rather than writing silly error messages");
 						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);
-						res = -1;
+					} else if (strncasecmp(column->type, "tinyint", 1) == 0) {
+						if (type != RQ_INTEGER1) {
+							ast_log(LOG_WARNING, "Realtime table %s@%s: column '%s' may not be large enough for the required data length: %d (detected unsigned tinyint)\n", tablename, database, column->name, size);
+							res = -1;
+						}
+					} else if (strncasecmp(column->type, "smallint", 1) == 0) {
+						if (type != RQ_UINTEGER1 && type != RQ_INTEGER1 && type != RQ_INTEGER2) {
+							ast_log(LOG_WARNING, "Realtime table %s@%s: column '%s' may not be large enough for the required data length: %d (detected unsigned smallint)\n", tablename, database, column->name, size);
+							res = -1;
+						}
+					} else if (strncasecmp(column->type, "mediumint", 1) == 0) {
+						if (type != RQ_UINTEGER1 && type != RQ_INTEGER1 &&
+							type != RQ_UINTEGER2 && type != RQ_INTEGER2 &&
+							type != RQ_INTEGER3) {
+							ast_log(LOG_WARNING, "Realtime table %s@%s: column '%s' may not be large enough for the required data length: %d (detected unsigned mediumint)\n", tablename, database, column->name, size);
+							res = -1;
+						}
+					} else if (strncasecmp(column->type, "int", 1) == 0) {
+						if (type != RQ_UINTEGER1 && type != RQ_INTEGER1 &&
+							type != RQ_UINTEGER2 && type != RQ_INTEGER2 &&
+							type != RQ_UINTEGER3 && type != RQ_INTEGER3 &&
+							type != RQ_INTEGER4) {
+							ast_log(LOG_WARNING, "Realtime table %s@%s: column '%s' may not be large enough for the required data length: %d (detected unsigned int)\n", tablename, database, column->name, size);
+							res = -1;
+						}
+					} else if (strncasecmp(column->type, "bigint", 1) == 0) {
+						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) {
+							ast_log(LOG_WARNING, "Realtime table %s@%s: column '%s' may not be large enough for the required data length: %d (detected unsigned bigint)\n", tablename, database, column->name, size);
+							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 */
@@ -870,8 +934,40 @@
 
 				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, "%sINT(%d)", size <= 3 ? "TINY" : size <= 5 ? "SMALL" : size <= 8 ? "MEDIUM" : size <= 11 ? "" : "BIG", size);
+				} else if (type == RQ_UINTEGER1 || type == RQ_UINTEGER2 || type == RQ_UINTEGER3 || type == RQ_UINTEGER4 || type == RQ_UINTEGER8) {
+					if (type == RQ_UINTEGER1) {
+						ast_str_set(&fieldtype, 0, "TINYINT(3) UNSIGNED");
+					} else if (type == RQ_UINTEGER2) {
+						ast_str_set(&fieldtype, 0, "SMALLINT(5) UNSIGNED");
+					} else if (type == RQ_UINTEGER3) {
+						ast_str_set(&fieldtype, 0, "MEDIUMINT(8) UNSIGNED");
+					} else if (type == RQ_UINTEGER4) {
+						ast_str_set(&fieldtype, 0, "INT(10) UNSIGNED");
+					} else if (type == RQ_UINTEGER8) {
+						ast_str_set(&fieldtype, 0, "BIGINT(20) UNSIGNED");
+					} else {
+						ast_free(sql);
+						ast_free(fieldtype);
+						ast_log(LOG_WARNING, "Somebody should check this code for a rather large bug... it's about to squash Tokyo.\n");
+						continue;
+					}
+				} else if (ast_rq_is_int(type)) {
+					if (type == RQ_INTEGER1) {
+						ast_str_set(&fieldtype, 0, "TINYINT(3)");
+					} else if (type == RQ_INTEGER2) {
+						ast_str_set(&fieldtype, 0, "SMALLINT(5)");
+					} else if (type == RQ_INTEGER3) {
+						ast_str_set(&fieldtype, 0, "MEDIUMINT(8)");
+					} else if (type == RQ_INTEGER4) {
+						ast_str_set(&fieldtype, 0, "INT(10)");
+					} else if (type == RQ_INTEGER8) {
+						ast_str_set(&fieldtype, 0, "BIGINT(20)");
+					} else {
+						ast_free(sql);
+						ast_free(fieldtype);
+						ast_log(LOG_WARNING, "Somebody should check this code for a rather large bug... it's about to eat Cincinnati.\n");
+						continue;
+					}
 				} else if (type == RQ_FLOAT) {
 					ast_str_set(&fieldtype, 0, "FLOAT");
 				} else if (type == RQ_DATE) {




More information about the svn-commits mailing list