147
143
'''col_definition : identifier data_type nullable_constraint default_p auto_increment_p unique_p primary_key comment_p'''
148
144
p[0]= ColumnDefinition(p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8])
151
146
def p_nullable_constraint(p):
152
147
'''nullable_constraint : NOT NULL
283
268
def p_optional_temporary(p):
284
'''temporary : TEMPORARY
269
'''temporary : TEMPORARY
286
# Returns True if the TEMPORARY phrase appeared, False otherwise
271
# Returns True if the TEMPORARY phrase appeared, False otherwise
289
274
def p_create_schema(p):
290
'''statement_type : create_schema_simple
275
'''statement_type : create_schema_simple
291
276
| create_schema_with_charset
292
277
| create_schema_with_collation
293
278
| create_schema_with_charset_and_collation'''
296
281
def p_create_schema_simple(p):
297
'''create_schema_simple : CREATE schema_or_database if_not_exists identifier'''
298
p[0]= CreateSchemaStatement(p[4], None, None, p[3])
282
'''create_schema_simple : CREATE schema_or_database if_not_exists identifier'''
283
p[0]= CreateSchemaStatement(p[4], None, None, p[3])
300
285
def p_create_schema_with_charset(p):
301
'''create_schema_with_charset : CREATE schema_or_database if_not_exists identifier charset identifier'''
302
p[0]= CreateSchemaStatement(p[4], p[6], None, p[3])
286
'''create_schema_with_charset : CREATE schema_or_database if_not_exists identifier charset identifier'''
287
p[0]= CreateSchemaStatement(p[4], p[6], None, p[3])
304
289
def p_create_schema_with_collation(p):
305
'''create_schema_with_collation : CREATE schema_or_database if_not_exists identifier COLLATE identifier'''
306
p[0]= CreateSchemaStatement(p[4], None, p[6], p[3])
290
'''create_schema_with_collation : CREATE schema_or_database if_not_exists identifier COLLATE identifier'''
291
p[0]= CreateSchemaStatement(p[4], None, p[6], p[3])
308
293
def p_create_schema_with_charset_and_collation(p):
309
'''create_schema_with_charset_and_collation : CREATE schema_or_database if_not_exists identifier charset identifier COLLATE identifier'''
310
p[0]= CreateSchemaStatement(p[4], p[6], p[8], p[3])
294
'''create_schema_with_charset_and_collation : CREATE schema_or_database if_not_exists identifier charset identifier COLLATE identifier'''
295
p[0]= CreateSchemaStatement(p[4], p[6], p[8], p[3])
312
297
def p_optional_if_not_exists(p):
313
298
'''if_not_exists : IF NOT EXISTS
315
# Returns True if the IF NOT EXISTS phrase appeared, False otherwise
300
# Returns True if the IF NOT EXISTS phrase appeared, False otherwise
318
303
def p_schema_or_database(p):
319
304
'''schema_or_database : SCHEMA
367
pass # an empty rule that represents an optional
348
pass # an empty rule that represents an optional piece
371
# Called when a syntax or parse error occurs
372
print "A parse error occurred at token %s" % p
351
# Called when a syntax or parse error occurs
352
print "A parse error occurred at token %s" % p
374
354
# Create the parser
375
355
parser= yacc.yacc(debug= False)
377
357
def parse_string(subject):
379
return parser.parse(subject)
380
except Exception as e:
359
return parser.parse(subject)
360
except Exception as e: