diff --git a/grammar/13-01-14-create-table.pegjs b/grammar/13-01-14-create-table.pegjs index 97aeb2b..5207d7c 100644 --- a/grammar/13-01-14-create-table.pegjs +++ b/grammar/13-01-14-create-table.pegjs @@ -42,7 +42,7 @@ TABLE_PROPERTIES props.comment = comment; return props; } - / "IF"i _ "NOT"i _ "EXIST" "S"i? _ props:TABLE_PROPERTIES { + / "IF"i _ "NOT"i _ "EXIST"i "S"i? _ props:TABLE_PROPERTIES { props.ifNotExists = true; return props; } @@ -94,9 +94,13 @@ CREATE_DEFINITION_CONSTRAINT references: ref }; } - / "UNIQUE"i __ type:("KEY"i/"INDEX"i)? - name:(__ name:(ID/STRING) {return name;})? _ "(" _ idlist:ID_LIST ")" _ + / "UNIQUE"i _ type:("KEY"i/"INDEX"i)? + name:(_ name:(ID/STRING) {return name;})? _ "(" _ idlist:INDEX_COL_NAME_LIST ")" _ { + if(!key && name && name.match(/KEY|INDEX/i)) { + key = name + name = undefined + } var key = { type: "CONSTRAINT", constraint: (type ? type.toUpperCase() : 'INDEX'), @@ -108,7 +112,7 @@ CREATE_DEFINITION_CONSTRAINT return key; } / unique:("UNIQUE"i __)? type:("KEY"i/"INDEX"i) - name:(__ name:(ID/STRING) {return name;})? _ "(" _ idlist:ID_LIST ")" _ + name:(__ name:(ID/STRING) {return name;})? _ "(" _ idlist:INDEX_COL_NAME_LIST ")" _ { var key = { type: "CONSTRAINT", @@ -148,6 +152,19 @@ ID_LIST STRING_ID_LIST = id:(STRING/ID) _ rest:(',' _ id2:(STRING/ID) _ { return id2; })* { rest.unshift(id); return rest; } +INDEX_COL_NAME_LIST + = index_col_name:INDEX_COL_NAME _ rest:(',' _ index_col_name2:INDEX_COL_NAME _ { return index_col_name2; })* { rest.unshift(index_col_name); return rest; } + +INDEX_COL_NAME + = id:ID length:TYPE_LENGTH { + var key = { + id: id, + } + if(length) + key.length = length + return key + } + NUMERIC_TYPE_LENGTH = _ "(" _ length:POSITIVE_INTEGER _ "," _ decimals:POSITIVE_INTEGER _ ")" { @@ -206,6 +223,13 @@ COLUMN_TYPE_PROPERTIES "Column type properties" if(length) props.length = length; return props; } + / _ ("VARBINARY"i/"VARCHAR"i) length:TYPE_LENGTH _ "BINARY"i _ props:COLUMN_TYPE_PROPERTIES { + if(props.type) + throw new SyntaxError("Ambiguous type"); + props.type = 'VARBINARY'; + if(length) props.length = length; + return props; + } / _ ("VARCHAR"i/"CHARACTER"i __ "VARYING"i) length:TYPE_LENGTH props:COLUMN_TYPE_PROPERTIES { if(props.type) throw new SyntaxError("Ambiguous type"); @@ -241,6 +265,12 @@ COLUMN_TYPE_PROPERTIES "Column type properties" if(length) props.length = length; return props; } + / _ "BOOLEAN"i _ props:COLUMN_TYPE_PROPERTIES { + if(props.type) + throw new SyntaxError("Ambiguous type"); + props.type = 'BOOLEAN'; + return props; + } / _ "ENUM"i _ "(" values:STRING_ID_LIST ")" _ props:COLUMN_TYPE_PROPERTIES { if(props.type) throw new SyntaxError("Ambiguous type"); @@ -248,6 +278,13 @@ COLUMN_TYPE_PROPERTIES "Column type properties" props.values = values; return props; } + / _ "SET"i _ "(" values:STRING_ID_LIST ")" _ props:COLUMN_TYPE_PROPERTIES { + if(props.type) + throw new SyntaxError("Ambiguous type"); + props.type = 'SET'; + props.values = values; + return props; + } / _ "UNSIGNED"i _ props:COLUMN_TYPE_PROPERTIES { props.unsigned=true; return props; @@ -287,13 +324,12 @@ COLUMN_TYPE_PROPERTIES "Column type properties" return props; } / _ "DEFAULT"i __ value:CONSTANT_EXPRESSION props:COLUMN_TYPE_PROPERTIES { + if (value.toSql) { // @@@ FIXME. much ad-hock + value = value.toSql() + } props.default = value; return props; } - / _ "DEFAULT"i __ CURRENT_TIMESTAMP props:COLUMN_TYPE_PROPERTIES { - props.default = 'CURRENT_TIMESTAMP'; - return props; - } / _ "ON"i _ "UPDATE"i _ val:CURRENT_TIMESTAMP _ props:COLUMN_TYPE_PROPERTIES { props.onUpdate = val; return props; @@ -303,4 +339,3 @@ COLUMN_TYPE_PROPERTIES "Column type properties" return props; } / _ { return {}; } - diff --git a/lib/parse-options.js b/lib/parse-options.js index 73ad4d3..9a64661 100644 --- a/lib/parse-options.js +++ b/lib/parse-options.js @@ -123,7 +123,7 @@ ParseOptions.prototype.resolveConstantExpressionObject = function(expr) { return this.resolveConstantExpressionBinary(expr); } - throw new Error("Cannot resolve expression as a constant: " + expr); + throw new Error("Cannot resolve expression as a constant: [" + expr + "]"); }; @@ -206,10 +206,10 @@ ParseOptions.prototype.resolveConstantExpression = function(expr) { return expr; case 'string': return expr; + case 'boolean': + return expr; case 'object': return this.resolveConstantExpressionObject(expr); } - throw new Error("Cannot resolve expression as a constant"); + throw new Error("Cannot resolve expression as a constant [" + typeof expr + "][" + expr + "]"); }; - - diff --git a/lib/sqljs-parser.js b/lib/sqljs-parser.js index ab2aa23..c914021 100644 --- a/lib/sqljs-parser.js +++ b/lib/sqljs-parser.js @@ -100,6 +100,8 @@ module.exports = (function(){ "CONSTRAINT_NAME_OPT": parse_CONSTRAINT_NAME_OPT, "ID_LIST": parse_ID_LIST, "STRING_ID_LIST": parse_STRING_ID_LIST, + "INDEX_COL_NAME_LIST": parse_INDEX_COL_NAME_LIST, + "INDEX_COL_NAME": parse_INDEX_COL_NAME, "NUMERIC_TYPE_LENGTH": parse_NUMERIC_TYPE_LENGTH, "TYPE_LENGTH": parse_TYPE_LENGTH, "COLUMN_TYPE_PROPERTIES": parse_COLUMN_TYPE_PROPERTIES, @@ -7117,8 +7119,8 @@ module.exports = (function(){ if (result2 !== null) { result3 = parse__(); if (result3 !== null) { - if (input.substr(pos, 5) === "EXIST") { - result4 = "EXIST"; + if (input.substr(pos, 5).toLowerCase() === "exist") { + result4 = input.substr(pos, 5); pos += 5; } else { result4 = null; @@ -7966,7 +7968,7 @@ module.exports = (function(){ } } if (result0 !== null) { - result1 = parse___(); + result1 = parse__(); if (result1 !== null) { if (input.substr(pos, 3).toLowerCase() === "key") { result2 = input.substr(pos, 3); @@ -7992,7 +7994,7 @@ module.exports = (function(){ if (result2 !== null) { pos2 = pos; pos3 = pos; - result3 = parse___(); + result3 = parse__(); if (result3 !== null) { result4 = parse_ID(); if (result4 === null) { @@ -8030,7 +8032,7 @@ module.exports = (function(){ if (result5 !== null) { result6 = parse__(); if (result6 !== null) { - result7 = parse_ID_LIST(); + result7 = parse_INDEX_COL_NAME_LIST(); if (result7 !== null) { if (input.charCodeAt(pos) === 41) { result8 = ")"; @@ -8087,6 +8089,10 @@ module.exports = (function(){ } if (result0 !== null) { result0 = (function(offset, type, name, idlist) { + if(!key && name && name.match(/KEY|INDEX/i)) { + key = name + name = undefined + } var key = { type: "CONSTRAINT", constraint: (type ? type.toUpperCase() : 'INDEX'), @@ -8189,7 +8195,7 @@ module.exports = (function(){ if (result4 !== null) { result5 = parse__(); if (result5 !== null) { - result6 = parse_ID_LIST(); + result6 = parse_INDEX_COL_NAME_LIST(); if (result6 !== null) { if (input.charCodeAt(pos) === 41) { result7 = ")"; @@ -8710,6 +8716,184 @@ module.exports = (function(){ return result0; } + function parse_INDEX_COL_NAME_LIST() { + var cacheKey = "INDEX_COL_NAME_LIST@" + pos; + var cachedResult = cache[cacheKey]; + if (cachedResult) { + pos = cachedResult.nextPos; + return cachedResult.result; + } + + var result0, result1, result2, result3, result4, result5, result6; + var pos0, pos1, pos2, pos3; + + pos0 = pos; + pos1 = pos; + result0 = parse_INDEX_COL_NAME(); + if (result0 !== null) { + result1 = parse__(); + if (result1 !== null) { + result2 = []; + pos2 = pos; + pos3 = pos; + if (input.charCodeAt(pos) === 44) { + result3 = ","; + pos++; + } else { + result3 = null; + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + if (result3 !== null) { + result4 = parse__(); + if (result4 !== null) { + result5 = parse_INDEX_COL_NAME(); + if (result5 !== null) { + result6 = parse__(); + if (result6 !== null) { + result3 = [result3, result4, result5, result6]; + } else { + result3 = null; + pos = pos3; + } + } else { + result3 = null; + pos = pos3; + } + } else { + result3 = null; + pos = pos3; + } + } else { + result3 = null; + pos = pos3; + } + if (result3 !== null) { + result3 = (function(offset, index_col_name2) { return index_col_name2; })(pos2, result3[2]); + } + if (result3 === null) { + pos = pos2; + } + while (result3 !== null) { + result2.push(result3); + pos2 = pos; + pos3 = pos; + if (input.charCodeAt(pos) === 44) { + result3 = ","; + pos++; + } else { + result3 = null; + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + if (result3 !== null) { + result4 = parse__(); + if (result4 !== null) { + result5 = parse_INDEX_COL_NAME(); + if (result5 !== null) { + result6 = parse__(); + if (result6 !== null) { + result3 = [result3, result4, result5, result6]; + } else { + result3 = null; + pos = pos3; + } + } else { + result3 = null; + pos = pos3; + } + } else { + result3 = null; + pos = pos3; + } + } else { + result3 = null; + pos = pos3; + } + if (result3 !== null) { + result3 = (function(offset, index_col_name2) { return index_col_name2; })(pos2, result3[2]); + } + if (result3 === null) { + pos = pos2; + } + } + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + if (result0 !== null) { + result0 = (function(offset, index_col_name, rest) { rest.unshift(index_col_name); return rest; })(pos0, result0[0], result0[2]); + } + if (result0 === null) { + pos = pos0; + } + + cache[cacheKey] = { + nextPos: pos, + result: result0 + }; + return result0; + } + + function parse_INDEX_COL_NAME() { + var cacheKey = "INDEX_COL_NAME@" + pos; + var cachedResult = cache[cacheKey]; + if (cachedResult) { + pos = cachedResult.nextPos; + return cachedResult.result; + } + + var result0, result1; + var pos0, pos1; + + pos0 = pos; + pos1 = pos; + result0 = parse_ID(); + if (result0 !== null) { + result1 = parse_TYPE_LENGTH(); + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + if (result0 !== null) { + result0 = (function(offset, id, length) { + var key = { + id: id, + } + if(length) + key.length = length + return key + })(pos0, result0[0], result0[1]); + } + if (result0 === null) { + pos = pos0; + } + + cache[cacheKey] = { + nextPos: pos, + result: result0 + }; + return result0; + } + function parse_NUMERIC_TYPE_LENGTH() { var cacheKey = "NUMERIC_TYPE_LENGTH@" + pos; var cachedResult = cache[cacheKey]; @@ -9473,59 +9657,58 @@ module.exports = (function(){ pos1 = pos; result0 = parse__(); if (result0 !== null) { - if (input.substr(pos, 7).toLowerCase() === "varchar") { - result1 = input.substr(pos, 7); - pos += 7; + if (input.substr(pos, 9).toLowerCase() === "varbinary") { + result1 = input.substr(pos, 9); + pos += 9; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"VARCHAR\""); + matchFailed("\"VARBINARY\""); } } if (result1 === null) { - pos2 = pos; - if (input.substr(pos, 9).toLowerCase() === "character") { - result1 = input.substr(pos, 9); - pos += 9; + if (input.substr(pos, 7).toLowerCase() === "varchar") { + result1 = input.substr(pos, 7); + pos += 7; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"CHARACTER\""); + matchFailed("\"VARCHAR\""); } } - if (result1 !== null) { - result2 = parse___(); - if (result2 !== null) { - if (input.substr(pos, 7).toLowerCase() === "varying") { - result3 = input.substr(pos, 7); - pos += 7; + } + if (result1 !== null) { + result2 = parse_TYPE_LENGTH(); + if (result2 !== null) { + result3 = parse__(); + if (result3 !== null) { + if (input.substr(pos, 6).toLowerCase() === "binary") { + result4 = input.substr(pos, 6); + pos += 6; } else { - result3 = null; + result4 = null; if (reportFailures === 0) { - matchFailed("\"VARYING\""); + matchFailed("\"BINARY\""); } } - if (result3 !== null) { - result1 = [result1, result2, result3]; + if (result4 !== null) { + result5 = parse__(); + if (result5 !== null) { + result6 = parse_COLUMN_TYPE_PROPERTIES(); + if (result6 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } } else { - result1 = null; - pos = pos2; + result0 = null; + pos = pos1; } - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - } - if (result1 !== null) { - result2 = parse_TYPE_LENGTH(); - if (result2 !== null) { - result3 = parse_COLUMN_TYPE_PROPERTIES(); - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; } else { result0 = null; pos = pos1; @@ -9546,10 +9729,10 @@ module.exports = (function(){ result0 = (function(offset, length, props) { if(props.type) throw new SyntaxError("Ambiguous type"); - props.type = 'VARCHAR'; + props.type = 'VARBINARY'; if(length) props.length = length; return props; - })(pos0, result0[2], result0[3]); + })(pos0, result0[2], result0[6]); } if (result0 === null) { pos = pos0; @@ -9559,16 +9742,17 @@ module.exports = (function(){ pos1 = pos; result0 = parse__(); if (result0 !== null) { - if (input.substr(pos, 4).toLowerCase() === "char") { - result1 = input.substr(pos, 4); - pos += 4; + if (input.substr(pos, 7).toLowerCase() === "varchar") { + result1 = input.substr(pos, 7); + pos += 7; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"CHAR\""); + matchFailed("\"VARCHAR\""); } } if (result1 === null) { + pos2 = pos; if (input.substr(pos, 9).toLowerCase() === "character") { result1 = input.substr(pos, 9); pos += 9; @@ -9578,6 +9762,32 @@ module.exports = (function(){ matchFailed("\"CHARACTER\""); } } + if (result1 !== null) { + result2 = parse___(); + if (result2 !== null) { + if (input.substr(pos, 7).toLowerCase() === "varying") { + result3 = input.substr(pos, 7); + pos += 7; + } else { + result3 = null; + if (reportFailures === 0) { + matchFailed("\"VARYING\""); + } + } + if (result3 !== null) { + result1 = [result1, result2, result3]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } } if (result1 !== null) { result2 = parse_TYPE_LENGTH(); @@ -9605,7 +9815,7 @@ module.exports = (function(){ result0 = (function(offset, length, props) { if(props.type) throw new SyntaxError("Ambiguous type"); - props.type = 'CHAR'; + props.type = 'VARCHAR'; if(length) props.length = length; return props; })(pos0, result0[2], result0[3]); @@ -9618,72 +9828,39 @@ module.exports = (function(){ pos1 = pos; result0 = parse__(); if (result0 !== null) { - pos2 = pos; - if (input.substr(pos, 4).toLowerCase() === "tiny") { + if (input.substr(pos, 4).toLowerCase() === "char") { result1 = input.substr(pos, 4); pos += 4; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"TINY\""); + matchFailed("\"CHAR\""); } } if (result1 === null) { - if (input.substr(pos, 6).toLowerCase() === "medium") { - result1 = input.substr(pos, 6); - pos += 6; + if (input.substr(pos, 9).toLowerCase() === "character") { + result1 = input.substr(pos, 9); + pos += 9; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"MEDIUM\""); - } - } - if (result1 === null) { - if (input.substr(pos, 4).toLowerCase() === "long") { - result1 = input.substr(pos, 4); - pos += 4; - } else { - result1 = null; - if (reportFailures === 0) { - matchFailed("\"LONG\""); - } + matchFailed("\"CHARACTER\""); } } } - result1 = result1 !== null ? result1 : ""; if (result1 !== null) { - result2 = parse__(); + result2 = parse_TYPE_LENGTH(); if (result2 !== null) { - result1 = [result1, result2]; + result3 = parse_COLUMN_TYPE_PROPERTIES(); + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos1; + } } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - if (result1 !== null) { - if (input.substr(pos, 4).toLowerCase() === "text") { - result2 = input.substr(pos, 4); - pos += 4; - } else { - result2 = null; - if (reportFailures === 0) { - matchFailed("\"TEXT\""); - } - } - if (result2 !== null) { - result3 = parse_COLUMN_TYPE_PROPERTIES(); - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; + result0 = null; + pos = pos1; } } else { result0 = null; @@ -9694,12 +9871,13 @@ module.exports = (function(){ pos = pos1; } if (result0 !== null) { - result0 = (function(offset, prefix, props) { + result0 = (function(offset, length, props) { if(props.type) throw new SyntaxError("Ambiguous type"); - props.type = typeof prefix !== 'undefined' ? prefix.toUpperCase()+'TEXT' : 'TEXT'; + props.type = 'CHAR'; + if(length) props.length = length; return props; - })(pos0, result0[1][0], result0[3]); + })(pos0, result0[2], result0[3]); } if (result0 === null) { pos = pos0; @@ -9755,13 +9933,13 @@ module.exports = (function(){ pos = pos2; } if (result1 !== null) { - if (input.substr(pos, 4).toLowerCase() === "blob") { + if (input.substr(pos, 4).toLowerCase() === "text") { result2 = input.substr(pos, 4); pos += 4; } else { result2 = null; if (reportFailures === 0) { - matchFailed("\"BLOB\""); + matchFailed("\"TEXT\""); } } if (result2 !== null) { @@ -9788,7 +9966,7 @@ module.exports = (function(){ result0 = (function(offset, prefix, props) { if(props.type) throw new SyntaxError("Ambiguous type"); - props.type = typeof prefix !== 'undefined' ? prefix.toUpperCase()+'BLOB' : 'BLOB'; + props.type = typeof prefix !== 'undefined' ? prefix.toUpperCase()+'TEXT' : 'TEXT'; return props; })(pos0, result0[1][0], result0[3]); } @@ -9800,71 +9978,65 @@ module.exports = (function(){ pos1 = pos; result0 = parse__(); if (result0 !== null) { - if (input.substr(pos, 8).toLowerCase() === "datetime") { - result1 = input.substr(pos, 8); - pos += 8; + pos2 = pos; + if (input.substr(pos, 4).toLowerCase() === "tiny") { + result1 = input.substr(pos, 4); + pos += 4; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"DATETIME\""); + matchFailed("\"TINY\""); } } if (result1 === null) { - if (input.substr(pos, 4).toLowerCase() === "date") { - result1 = input.substr(pos, 4); - pos += 4; + if (input.substr(pos, 6).toLowerCase() === "medium") { + result1 = input.substr(pos, 6); + pos += 6; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"DATE\""); + matchFailed("\"MEDIUM\""); } } if (result1 === null) { - if (input.substr(pos, 9).toLowerCase() === "timestamp") { - result1 = input.substr(pos, 9); - pos += 9; + if (input.substr(pos, 4).toLowerCase() === "long") { + result1 = input.substr(pos, 4); + pos += 4; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"TIMESTAMP\""); - } - } - if (result1 === null) { - if (input.substr(pos, 4).toLowerCase() === "time") { - result1 = input.substr(pos, 4); - pos += 4; - } else { - result1 = null; - if (reportFailures === 0) { - matchFailed("\"TIME\""); - } - } - if (result1 === null) { - if (input.substr(pos, 4).toLowerCase() === "year") { - result1 = input.substr(pos, 4); - pos += 4; - } else { - result1 = null; - if (reportFailures === 0) { - matchFailed("\"YEAR\""); - } - } + matchFailed("\"LONG\""); } } } } + result1 = result1 !== null ? result1 : ""; + if (result1 !== null) { + result2 = parse__(); + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } if (result1 !== null) { - result2 = parse_TYPE_LENGTH(); + if (input.substr(pos, 4).toLowerCase() === "blob") { + result2 = input.substr(pos, 4); + pos += 4; + } else { + result2 = null; + if (reportFailures === 0) { + matchFailed("\"BLOB\""); + } + } if (result2 !== null) { - result3 = parse__(); + result3 = parse_COLUMN_TYPE_PROPERTIES(); if (result3 !== null) { - result4 = parse_COLUMN_TYPE_PROPERTIES(); - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos1; - } + result0 = [result0, result1, result2, result3]; } else { result0 = null; pos = pos1; @@ -9882,13 +10054,12 @@ module.exports = (function(){ pos = pos1; } if (result0 !== null) { - result0 = (function(offset, type, length, props) { + result0 = (function(offset, prefix, props) { if(props.type) throw new SyntaxError("Ambiguous type"); - props.type = type.toUpperCase(); - if(length) props.length = length; + props.type = typeof prefix !== 'undefined' ? prefix.toUpperCase()+'BLOB' : 'BLOB'; return props; - })(pos0, result0[1], result0[2], result0[4]); + })(pos0, result0[1][0], result0[3]); } if (result0 === null) { pos = pos0; @@ -9898,57 +10069,67 @@ module.exports = (function(){ pos1 = pos; result0 = parse__(); if (result0 !== null) { - if (input.substr(pos, 4).toLowerCase() === "enum") { - result1 = input.substr(pos, 4); - pos += 4; + if (input.substr(pos, 8).toLowerCase() === "datetime") { + result1 = input.substr(pos, 8); + pos += 8; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"ENUM\""); + matchFailed("\"DATETIME\""); } } - if (result1 !== null) { - result2 = parse__(); - if (result2 !== null) { - if (input.charCodeAt(pos) === 40) { - result3 = "("; - pos++; + if (result1 === null) { + if (input.substr(pos, 4).toLowerCase() === "date") { + result1 = input.substr(pos, 4); + pos += 4; + } else { + result1 = null; + if (reportFailures === 0) { + matchFailed("\"DATE\""); + } + } + if (result1 === null) { + if (input.substr(pos, 9).toLowerCase() === "timestamp") { + result1 = input.substr(pos, 9); + pos += 9; } else { - result3 = null; + result1 = null; if (reportFailures === 0) { - matchFailed("\"(\""); + matchFailed("\"TIMESTAMP\""); } } - if (result3 !== null) { - result4 = parse_STRING_ID_LIST(); - if (result4 !== null) { - if (input.charCodeAt(pos) === 41) { - result5 = ")"; - pos++; + if (result1 === null) { + if (input.substr(pos, 4).toLowerCase() === "time") { + result1 = input.substr(pos, 4); + pos += 4; + } else { + result1 = null; + if (reportFailures === 0) { + matchFailed("\"TIME\""); + } + } + if (result1 === null) { + if (input.substr(pos, 4).toLowerCase() === "year") { + result1 = input.substr(pos, 4); + pos += 4; } else { - result5 = null; + result1 = null; if (reportFailures === 0) { - matchFailed("\")\""); - } - } - if (result5 !== null) { - result6 = parse__(); - if (result6 !== null) { - result7 = parse_COLUMN_TYPE_PROPERTIES(); - if (result7 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; + matchFailed("\"YEAR\""); } - } else { - result0 = null; - pos = pos1; } + } + } + } + } + if (result1 !== null) { + result2 = parse_TYPE_LENGTH(); + if (result2 !== null) { + result3 = parse__(); + if (result3 !== null) { + result4 = parse_COLUMN_TYPE_PROPERTIES(); + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; } else { result0 = null; pos = pos1; @@ -9970,13 +10151,13 @@ module.exports = (function(){ pos = pos1; } if (result0 !== null) { - result0 = (function(offset, values, props) { + result0 = (function(offset, type, length, props) { if(props.type) throw new SyntaxError("Ambiguous type"); - props.type = 'ENUM'; - props.values = values; + props.type = type.toUpperCase(); + if(length) props.length = length; return props; - })(pos0, result0[4], result0[7]); + })(pos0, result0[1], result0[2], result0[4]); } if (result0 === null) { pos = pos0; @@ -9986,13 +10167,13 @@ module.exports = (function(){ pos1 = pos; result0 = parse__(); if (result0 !== null) { - if (input.substr(pos, 8).toLowerCase() === "unsigned") { - result1 = input.substr(pos, 8); - pos += 8; + if (input.substr(pos, 7).toLowerCase() === "boolean") { + result1 = input.substr(pos, 7); + pos += 7; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"UNSIGNED\""); + matchFailed("\"BOOLEAN\""); } } if (result1 !== null) { @@ -10019,9 +10200,11 @@ module.exports = (function(){ } if (result0 !== null) { result0 = (function(offset, props) { - props.unsigned=true; - return props; - })(pos0, result0[3]); + if(props.type) + throw new SyntaxError("Ambiguous type"); + props.type = 'BOOLEAN'; + return props; + })(pos0, result0[3]); } if (result0 === null) { pos = pos0; @@ -10031,21 +10214,61 @@ module.exports = (function(){ pos1 = pos; result0 = parse__(); if (result0 !== null) { - if (input.substr(pos, 6).toLowerCase() === "signed") { - result1 = input.substr(pos, 6); - pos += 6; + if (input.substr(pos, 4).toLowerCase() === "enum") { + result1 = input.substr(pos, 4); + pos += 4; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"SIGNED\""); + matchFailed("\"ENUM\""); } } if (result1 !== null) { result2 = parse__(); if (result2 !== null) { - result3 = parse_COLUMN_TYPE_PROPERTIES(); + if (input.charCodeAt(pos) === 40) { + result3 = "("; + pos++; + } else { + result3 = null; + if (reportFailures === 0) { + matchFailed("\"(\""); + } + } if (result3 !== null) { - result0 = [result0, result1, result2, result3]; + result4 = parse_STRING_ID_LIST(); + if (result4 !== null) { + if (input.charCodeAt(pos) === 41) { + result5 = ")"; + pos++; + } else { + result5 = null; + if (reportFailures === 0) { + matchFailed("\")\""); + } + } + if (result5 !== null) { + result6 = parse__(); + if (result6 !== null) { + result7 = parse_COLUMN_TYPE_PROPERTIES(); + if (result7 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } } else { result0 = null; pos = pos1; @@ -10063,10 +10286,13 @@ module.exports = (function(){ pos = pos1; } if (result0 !== null) { - result0 = (function(offset, props) { - props.signed=true; - return props; - })(pos0, result0[3]); + result0 = (function(offset, values, props) { + if(props.type) + throw new SyntaxError("Ambiguous type"); + props.type = 'ENUM'; + props.values = values; + return props; + })(pos0, result0[4], result0[7]); } if (result0 === null) { pos = pos0; @@ -10076,33 +10302,53 @@ module.exports = (function(){ pos1 = pos; result0 = parse__(); if (result0 !== null) { - if (input.substr(pos, 3).toLowerCase() === "not") { + if (input.substr(pos, 3).toLowerCase() === "set") { result1 = input.substr(pos, 3); pos += 3; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"NOT\""); + matchFailed("\"SET\""); } } if (result1 !== null) { result2 = parse__(); if (result2 !== null) { - if (input.substr(pos, 4).toLowerCase() === "null") { - result3 = input.substr(pos, 4); - pos += 4; + if (input.charCodeAt(pos) === 40) { + result3 = "("; + pos++; } else { result3 = null; if (reportFailures === 0) { - matchFailed("\"NULL\""); + matchFailed("\"(\""); } } if (result3 !== null) { - result4 = parse__(); + result4 = parse_STRING_ID_LIST(); if (result4 !== null) { - result5 = parse_COLUMN_TYPE_PROPERTIES(); + if (input.charCodeAt(pos) === 41) { + result5 = ")"; + pos++; + } else { + result5 = null; + if (reportFailures === 0) { + matchFailed("\")\""); + } + } if (result5 !== null) { - result0 = [result0, result1, result2, result3, result4, result5]; + result6 = parse__(); + if (result6 !== null) { + result7 = parse_COLUMN_TYPE_PROPERTIES(); + if (result7 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } } else { result0 = null; pos = pos1; @@ -10128,12 +10374,13 @@ module.exports = (function(){ pos = pos1; } if (result0 !== null) { - result0 = (function(offset, props) { - if(typeof props.notNull !== 'undefined') - throw new Error('NULL or NOT NULL?'); - props.notNull=true; + result0 = (function(offset, values, props) { + if(props.type) + throw new SyntaxError("Ambiguous type"); + props.type = 'SET'; + props.values = values; return props; - })(pos0, result0[5]); + })(pos0, result0[4], result0[7]); } if (result0 === null) { pos = pos0; @@ -10143,19 +10390,25 @@ module.exports = (function(){ pos1 = pos; result0 = parse__(); if (result0 !== null) { - if (input.substr(pos, 4).toLowerCase() === "null") { - result1 = input.substr(pos, 4); - pos += 4; + if (input.substr(pos, 8).toLowerCase() === "unsigned") { + result1 = input.substr(pos, 8); + pos += 8; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"NULL\""); + matchFailed("\"UNSIGNED\""); } } if (result1 !== null) { - result2 = parse_COLUMN_TYPE_PROPERTIES(); + result2 = parse__(); if (result2 !== null) { - result0 = [result0, result1, result2]; + result3 = parse_COLUMN_TYPE_PROPERTIES(); + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos1; + } } else { result0 = null; pos = pos1; @@ -10170,11 +10423,9 @@ module.exports = (function(){ } if (result0 !== null) { result0 = (function(offset, props) { - if(typeof props.notNull !== 'undefined') - throw new Error('NULL or NOT NULL?'); - props.notNull=false; - return props; - })(pos0, result0[2]); + props.unsigned=true; + return props; + })(pos0, result0[3]); } if (result0 === null) { pos = pos0; @@ -10184,49 +10435,21 @@ module.exports = (function(){ pos1 = pos; result0 = parse__(); if (result0 !== null) { - if (input.substr(pos, 7).toLowerCase() === "primary") { - result1 = input.substr(pos, 7); - pos += 7; + if (input.substr(pos, 6).toLowerCase() === "signed") { + result1 = input.substr(pos, 6); + pos += 6; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"PRIMARY\""); + matchFailed("\"SIGNED\""); } } if (result1 !== null) { - pos2 = pos; result2 = parse__(); if (result2 !== null) { - if (input.substr(pos, 3).toLowerCase() === "key") { - result3 = input.substr(pos, 3); - pos += 3; - } else { - result3 = null; - if (reportFailures === 0) { - matchFailed("\"KEY\""); - } - } - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - result2 = result2 !== null ? result2 : ""; - if (result2 !== null) { - result3 = parse__(); + result3 = parse_COLUMN_TYPE_PROPERTIES(); if (result3 !== null) { - result4 = parse_COLUMN_TYPE_PROPERTIES(); - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos1; - } + result0 = [result0, result1, result2, result3]; } else { result0 = null; pos = pos1; @@ -10245,9 +10468,9 @@ module.exports = (function(){ } if (result0 !== null) { result0 = (function(offset, props) { - props.primaryKey=true; - return props; - })(pos0, result0[4]); + props.signed=true; + return props; + })(pos0, result0[3]); } if (result0 === null) { pos = pos0; @@ -10257,32 +10480,37 @@ module.exports = (function(){ pos1 = pos; result0 = parse__(); if (result0 !== null) { - if (input.substr(pos, 4).toLowerCase() === "uniq") { - result1 = input.substr(pos, 4); - pos += 4; + if (input.substr(pos, 3).toLowerCase() === "not") { + result1 = input.substr(pos, 3); + pos += 3; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"UNIQ\""); + matchFailed("\"NOT\""); } } if (result1 !== null) { - if (input.substr(pos, 2).toLowerCase() === "ue") { - result2 = input.substr(pos, 2); - pos += 2; - } else { - result2 = null; - if (reportFailures === 0) { - matchFailed("\"UE\""); - } - } - result2 = result2 !== null ? result2 : ""; + result2 = parse__(); if (result2 !== null) { - result3 = parse__(); + if (input.substr(pos, 4).toLowerCase() === "null") { + result3 = input.substr(pos, 4); + pos += 4; + } else { + result3 = null; + if (reportFailures === 0) { + matchFailed("\"NULL\""); + } + } if (result3 !== null) { - result4 = parse_COLUMN_TYPE_PROPERTIES(); + result4 = parse__(); if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; + result5 = parse_COLUMN_TYPE_PROPERTIES(); + if (result5 !== null) { + result0 = [result0, result1, result2, result3, result4, result5]; + } else { + result0 = null; + pos = pos1; + } } else { result0 = null; pos = pos1; @@ -10305,9 +10533,11 @@ module.exports = (function(){ } if (result0 !== null) { result0 = (function(offset, props) { - props.unique=true; + if(typeof props.notNull !== 'undefined') + throw new Error('NULL or NOT NULL?'); + props.notNull=true; return props; - })(pos0, result0[4]); + })(pos0, result0[5]); } if (result0 === null) { pos = pos0; @@ -10317,71 +10547,19 @@ module.exports = (function(){ pos1 = pos; result0 = parse__(); if (result0 !== null) { - if (input.substr(pos, 4).toLowerCase() === "auto") { + if (input.substr(pos, 4).toLowerCase() === "null") { result1 = input.substr(pos, 4); pos += 4; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"AUTO\""); + matchFailed("\"NULL\""); } } if (result1 !== null) { - if (input.charCodeAt(pos) === 95) { - result2 = "_"; - pos++; - } else { - result2 = null; - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - if (result2 === null) { - result2 = parse__(); - } + result2 = parse_COLUMN_TYPE_PROPERTIES(); if (result2 !== null) { - if (input.substr(pos, 3).toLowerCase() === "inc") { - result3 = input.substr(pos, 3); - pos += 3; - } else { - result3 = null; - if (reportFailures === 0) { - matchFailed("\"INC\""); - } - } - if (result3 !== null) { - if (input.substr(pos, 6).toLowerCase() === "rement") { - result4 = input.substr(pos, 6); - pos += 6; - } else { - result4 = null; - if (reportFailures === 0) { - matchFailed("\"REMENT\""); - } - } - result4 = result4 !== null ? result4 : ""; - if (result4 !== null) { - result5 = parse__(); - if (result5 !== null) { - result6 = parse_COLUMN_TYPE_PROPERTIES(); - if (result6 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } + result0 = [result0, result1, result2]; } else { result0 = null; pos = pos1; @@ -10396,9 +10574,11 @@ module.exports = (function(){ } if (result0 !== null) { result0 = (function(offset, props) { - props.autoIncrement=true; + if(typeof props.notNull !== 'undefined') + throw new Error('NULL or NOT NULL?'); + props.notNull=false; return props; - })(pos0, result0[6]); + })(pos0, result0[2]); } if (result0 === null) { pos = pos0; @@ -10408,84 +10588,45 @@ module.exports = (function(){ pos1 = pos; result0 = parse__(); if (result0 !== null) { - if (input.substr(pos, 6).toLowerCase() === "collat") { - result1 = input.substr(pos, 6); - pos += 6; + if (input.substr(pos, 7).toLowerCase() === "primary") { + result1 = input.substr(pos, 7); + pos += 7; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"COLLAT\""); + matchFailed("\"PRIMARY\""); } } if (result1 !== null) { - if (input.substr(pos, 1).toLowerCase() === "e") { - result2 = input.substr(pos, 1); - pos++; - } else { - result2 = null; - if (reportFailures === 0) { - matchFailed("\"E\""); - } - } - if (result2 === null) { - if (input.substr(pos, 3).toLowerCase() === "ion") { - result2 = input.substr(pos, 3); + pos2 = pos; + result2 = parse__(); + if (result2 !== null) { + if (input.substr(pos, 3).toLowerCase() === "key") { + result3 = input.substr(pos, 3); pos += 3; } else { - result2 = null; + result3 = null; if (reportFailures === 0) { - matchFailed("\"ION\""); + matchFailed("\"KEY\""); } } - } - if (result2 !== null) { - pos2 = pos; - result3 = parse__(); if (result3 !== null) { - if (input.charCodeAt(pos) === 61) { - result4 = "="; - pos++; - } else { - result4 = null; - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - if (result4 !== null) { - result5 = parse__(); - if (result5 !== null) { - result3 = [result3, result4, result5]; - } else { - result3 = null; - pos = pos2; - } - } else { - result3 = null; - pos = pos2; - } + result2 = [result2, result3]; } else { - result3 = null; + result2 = null; pos = pos2; } - if (result3 === null) { - result3 = parse___(); - } + } else { + result2 = null; + pos = pos2; + } + result2 = result2 !== null ? result2 : ""; + if (result2 !== null) { + result3 = parse__(); if (result3 !== null) { - result4 = parse_COLLATION_NAME(); + result4 = parse_COLUMN_TYPE_PROPERTIES(); if (result4 !== null) { - result5 = parse__(); - if (result5 !== null) { - result6 = parse_COLUMN_TYPE_PROPERTIES(); - if (result6 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } + result0 = [result0, result1, result2, result3, result4]; } else { result0 = null; pos = pos1; @@ -10507,10 +10648,10 @@ module.exports = (function(){ pos = pos1; } if (result0 !== null) { - result0 = (function(offset, collate, props) { - props.collate = collate; + result0 = (function(offset, props) { + props.primaryKey=true; return props; - })(pos0, result0[4], result0[6]); + })(pos0, result0[4]); } if (result0 === null) { pos = pos0; @@ -10520,19 +10661,28 @@ module.exports = (function(){ pos1 = pos; result0 = parse__(); if (result0 !== null) { - if (input.substr(pos, 7).toLowerCase() === "default") { - result1 = input.substr(pos, 7); - pos += 7; + if (input.substr(pos, 4).toLowerCase() === "uniq") { + result1 = input.substr(pos, 4); + pos += 4; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"DEFAULT\""); + matchFailed("\"UNIQ\""); } } if (result1 !== null) { - result2 = parse___(); + if (input.substr(pos, 2).toLowerCase() === "ue") { + result2 = input.substr(pos, 2); + pos += 2; + } else { + result2 = null; + if (reportFailures === 0) { + matchFailed("\"UE\""); + } + } + result2 = result2 !== null ? result2 : ""; if (result2 !== null) { - result3 = parse_CONSTANT_EXPRESSION(); + result3 = parse__(); if (result3 !== null) { result4 = parse_COLUMN_TYPE_PROPERTIES(); if (result4 !== null) { @@ -10558,10 +10708,10 @@ module.exports = (function(){ pos = pos1; } if (result0 !== null) { - result0 = (function(offset, value, props) { - props.default = value; + result0 = (function(offset, props) { + props.unique=true; return props; - })(pos0, result0[3], result0[4]); + })(pos0, result0[4]); } if (result0 === null) { pos = pos0; @@ -10571,23 +10721,63 @@ module.exports = (function(){ pos1 = pos; result0 = parse__(); if (result0 !== null) { - if (input.substr(pos, 7).toLowerCase() === "default") { - result1 = input.substr(pos, 7); - pos += 7; + if (input.substr(pos, 4).toLowerCase() === "auto") { + result1 = input.substr(pos, 4); + pos += 4; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"DEFAULT\""); + matchFailed("\"AUTO\""); } } if (result1 !== null) { - result2 = parse___(); + if (input.charCodeAt(pos) === 95) { + result2 = "_"; + pos++; + } else { + result2 = null; + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + if (result2 === null) { + result2 = parse__(); + } if (result2 !== null) { - result3 = parse_CURRENT_TIMESTAMP(); + if (input.substr(pos, 3).toLowerCase() === "inc") { + result3 = input.substr(pos, 3); + pos += 3; + } else { + result3 = null; + if (reportFailures === 0) { + matchFailed("\"INC\""); + } + } if (result3 !== null) { - result4 = parse_COLUMN_TYPE_PROPERTIES(); + if (input.substr(pos, 6).toLowerCase() === "rement") { + result4 = input.substr(pos, 6); + pos += 6; + } else { + result4 = null; + if (reportFailures === 0) { + matchFailed("\"REMENT\""); + } + } + result4 = result4 !== null ? result4 : ""; if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; + result5 = parse__(); + if (result5 !== null) { + result6 = parse_COLUMN_TYPE_PROPERTIES(); + if (result6 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } } else { result0 = null; pos = pos1; @@ -10610,9 +10800,9 @@ module.exports = (function(){ } if (result0 !== null) { result0 = (function(offset, props) { - props.default = 'CURRENT_TIMESTAMP'; + props.autoIncrement=true; return props; - })(pos0, result0[4]); + })(pos0, result0[6]); } if (result0 === null) { pos = pos0; @@ -10622,41 +10812,76 @@ module.exports = (function(){ pos1 = pos; result0 = parse__(); if (result0 !== null) { - if (input.substr(pos, 2).toLowerCase() === "on") { - result1 = input.substr(pos, 2); - pos += 2; + if (input.substr(pos, 6).toLowerCase() === "collat") { + result1 = input.substr(pos, 6); + pos += 6; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"ON\""); + matchFailed("\"COLLAT\""); } } if (result1 !== null) { - result2 = parse__(); - if (result2 !== null) { - if (input.substr(pos, 6).toLowerCase() === "update") { - result3 = input.substr(pos, 6); - pos += 6; + if (input.substr(pos, 1).toLowerCase() === "e") { + result2 = input.substr(pos, 1); + pos++; + } else { + result2 = null; + if (reportFailures === 0) { + matchFailed("\"E\""); + } + } + if (result2 === null) { + if (input.substr(pos, 3).toLowerCase() === "ion") { + result2 = input.substr(pos, 3); + pos += 3; } else { - result3 = null; + result2 = null; if (reportFailures === 0) { - matchFailed("\"UPDATE\""); + matchFailed("\"ION\""); } } + } + if (result2 !== null) { + pos2 = pos; + result3 = parse__(); if (result3 !== null) { - result4 = parse__(); + if (input.charCodeAt(pos) === 61) { + result4 = "="; + pos++; + } else { + result4 = null; + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } if (result4 !== null) { - result5 = parse_CURRENT_TIMESTAMP(); + result5 = parse__(); if (result5 !== null) { - result6 = parse__(); + result3 = [result3, result4, result5]; + } else { + result3 = null; + pos = pos2; + } + } else { + result3 = null; + pos = pos2; + } + } else { + result3 = null; + pos = pos2; + } + if (result3 === null) { + result3 = parse___(); + } + if (result3 !== null) { + result4 = parse_COLLATION_NAME(); + if (result4 !== null) { + result5 = parse__(); + if (result5 !== null) { + result6 = parse_COLUMN_TYPE_PROPERTIES(); if (result6 !== null) { - result7 = parse_COLUMN_TYPE_PROPERTIES(); - if (result7 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; - } else { - result0 = null; - pos = pos1; - } + result0 = [result0, result1, result2, result3, result4, result5, result6]; } else { result0 = null; pos = pos1; @@ -10686,10 +10911,10 @@ module.exports = (function(){ pos = pos1; } if (result0 !== null) { - result0 = (function(offset, val, props) { - props.onUpdate = val; + result0 = (function(offset, collate, props) { + props.collate = collate; return props; - })(pos0, result0[5], result0[7]); + })(pos0, result0[4], result0[6]); } if (result0 === null) { pos = pos0; @@ -10699,49 +10924,19 @@ module.exports = (function(){ pos1 = pos; result0 = parse__(); if (result0 !== null) { - if (input.substr(pos, 7).toLowerCase() === "comment") { + if (input.substr(pos, 7).toLowerCase() === "default") { result1 = input.substr(pos, 7); pos += 7; } else { result1 = null; if (reportFailures === 0) { - matchFailed("\"COMMENT\""); + matchFailed("\"DEFAULT\""); } } if (result1 !== null) { - pos2 = pos; - result2 = parse__(); - if (result2 !== null) { - if (input.charCodeAt(pos) === 61) { - result3 = "="; - pos++; - } else { - result3 = null; - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - if (result3 !== null) { - result4 = parse__(); - if (result4 !== null) { - result2 = [result2, result3, result4]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - if (result2 === null) { - result2 = parse___(); - } + result2 = parse___(); if (result2 !== null) { - result3 = parse_STRING(); + result3 = parse_CONSTANT_EXPRESSION(); if (result3 !== null) { result4 = parse_COLUMN_TYPE_PROPERTIES(); if (result4 !== null) { @@ -10767,8 +10962,11 @@ module.exports = (function(){ pos = pos1; } if (result0 !== null) { - result0 = (function(offset, comment, props) { - props.comment = comment; + result0 = (function(offset, value, props) { + if (value.toSql) { + value = value.toSql() + } + props.default = value; return props; })(pos0, result0[3], result0[4]); } @@ -10777,13 +10975,173 @@ module.exports = (function(){ } if (result0 === null) { pos0 = pos; + pos1 = pos; result0 = parse__(); if (result0 !== null) { - result0 = (function(offset) { return {}; })(pos0); + if (input.substr(pos, 2).toLowerCase() === "on") { + result1 = input.substr(pos, 2); + pos += 2; + } else { + result1 = null; + if (reportFailures === 0) { + matchFailed("\"ON\""); + } + } + if (result1 !== null) { + result2 = parse__(); + if (result2 !== null) { + if (input.substr(pos, 6).toLowerCase() === "update") { + result3 = input.substr(pos, 6); + pos += 6; + } else { + result3 = null; + if (reportFailures === 0) { + matchFailed("\"UPDATE\""); + } + } + if (result3 !== null) { + result4 = parse__(); + if (result4 !== null) { + result5 = parse_CURRENT_TIMESTAMP(); + if (result5 !== null) { + result6 = parse__(); + if (result6 !== null) { + result7 = parse_COLUMN_TYPE_PROPERTIES(); + if (result7 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + if (result0 !== null) { + result0 = (function(offset, val, props) { + props.onUpdate = val; + return props; + })(pos0, result0[5], result0[7]); } if (result0 === null) { pos = pos0; } + if (result0 === null) { + pos0 = pos; + pos1 = pos; + result0 = parse__(); + if (result0 !== null) { + if (input.substr(pos, 7).toLowerCase() === "comment") { + result1 = input.substr(pos, 7); + pos += 7; + } else { + result1 = null; + if (reportFailures === 0) { + matchFailed("\"COMMENT\""); + } + } + if (result1 !== null) { + pos2 = pos; + result2 = parse__(); + if (result2 !== null) { + if (input.charCodeAt(pos) === 61) { + result3 = "="; + pos++; + } else { + result3 = null; + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + if (result3 !== null) { + result4 = parse__(); + if (result4 !== null) { + result2 = [result2, result3, result4]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + if (result2 === null) { + result2 = parse___(); + } + if (result2 !== null) { + result3 = parse_STRING(); + if (result3 !== null) { + result4 = parse_COLUMN_TYPE_PROPERTIES(); + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + if (result0 !== null) { + result0 = (function(offset, comment, props) { + props.comment = comment; + return props; + })(pos0, result0[3], result0[4]); + } + if (result0 === null) { + pos = pos0; + } + if (result0 === null) { + pos0 = pos; + result0 = parse__(); + if (result0 !== null) { + result0 = (function(offset) { return {}; })(pos0); + } + if (result0 === null) { + pos = pos0; + } + } + } } } } diff --git a/tests/parser/13-01-14-create-table.js b/tests/parser/13-01-14-create-table.js index 96a996d..8bbbafa 100644 --- a/tests/parser/13-01-14-create-table.js +++ b/tests/parser/13-01-14-create-table.js @@ -226,6 +226,89 @@ exports['Grammar: CREATE TABLE: valid input'] = rule_yields.bind(null, ], [ 'CREATE TABLE "a b c" ("x y z" integer)', result9 + ], [ + 'CREATE TABLE a (id integer, UNIQUE(id))', + [{ + statement: 'CREATE', + what: 'TABLE', + schema: undefined, + table: 'a', + definitions: [ { type: 'INT', name: 'id' }, + { type: 'CONSTRAINT', constraint: 'INDEX', unique: true, columns: [ {id: 'id'} ] }, + ] + }] + ], [ + 'CREATE TABLE a (id integer, UNIQUE INDEX(id))', + [{ + statement: 'CREATE', + what: 'TABLE', + schema: undefined, + table: 'a', + definitions: [ { type: 'INT', name: 'id' }, + { type: 'CONSTRAINT', constraint: 'INDEX', unique: true, columns: [ {id: 'id'} ] }, + ] + }] + ], [ + 'CREATE TABLE a (name varchar(255), UNIQUE INDEX(name(10)))', + [{ + statement: 'CREATE', + what: 'TABLE', + schema: undefined, + table: 'a', + definitions: [ { type: 'VARCHAR', name: 'name', length: 255 }, + { type: 'CONSTRAINT', constraint: 'INDEX', unique: true, columns: [ {id: 'name', length: 10, } ] }, + ] + }] + ], [ + 'CREATE TABLE a (opts SET("blue", "red", "yellow"))', + [{ + statement: 'CREATE', + what: 'TABLE', + schema: undefined, + table: 'a', + definitions: [ { type: 'SET', name: 'opts', values: [ 'blue', 'red', 'yellow', ] }, + ] + }] + ], [ + 'CREATE TABLE a (name VARCHAR(255) BINARY NOT NULL)', + [{ + statement: 'CREATE', + what: 'TABLE', + schema: undefined, + table: 'a', + definitions: [ { type: 'VARBINARY', name: 'name', length: 255, notNull: true }, + ] + }] + ], [ + 'CREATE TABLE a (flag BOOLEAN NOT NULL DEFAULT TRUE)', + [{ + statement: 'CREATE', + what: 'TABLE', + schema: undefined, + table: 'a', + definitions: [ { type: 'BOOLEAN', name: 'flag', default: true, notNull: true }, + ] + }] + ], [ + 'create table a if not exists (id number)', + [{ + statement: 'CREATE', + what: 'TABLE', + schema: undefined, + table: 'a', + ifNotExists: true, + definitions: [ { type: 'DECIMAL', name: 'id' }, + ] + }] + ], [ + 'create table a (d TIMESTAMP DEFAULT now())', + [{ + statement: 'CREATE', + what: 'TABLE', + schema: undefined, + table: 'a', + definitions: [ { type: 'TIMESTAMP', name: 'd', default: 'CURRENT_TIMESTAMP' }, ] + }] ] ], 'deepEqual' );