Revision 3082
Added by Aaron Marcuse-Kubitza over 12 years ago
sql.py | ||
---|---|---|
1142 | 1142 |
table = sql_gen.as_Table(table) |
1143 | 1143 |
return run_query(db, 'DROP TABLE IF EXISTS '+table.to_str(db)+' CASCADE') |
1144 | 1144 |
|
1145 |
def create_table(db, table, cols, has_pkey=True, col_indexes=True): |
|
1145 |
def create_table(db, table, cols=[], has_pkey=True, col_indexes=True, |
|
1146 |
like=None): |
|
1146 | 1147 |
'''Creates a table. |
1147 | 1148 |
@param cols [sql_gen.TypedCol,...] The column names and types |
1148 | 1149 |
@param has_pkey If set, the first column becomes the primary key. |
... | ... | |
1153 | 1154 |
''' |
1154 | 1155 |
table = sql_gen.as_Table(table) |
1155 | 1156 |
|
1157 |
if like != None: |
|
1158 |
cols = [sql_gen.CustomCode('LIKE '+like.to_str(db)+' INCLUDING ALL') |
|
1159 |
]+cols |
|
1156 | 1160 |
if has_pkey: |
1157 | 1161 |
cols[0] = pkey = copy.copy(cols[0]) # don't modify input! |
1158 | 1162 |
pkey.constraints = 'PRIMARY KEY' |
1159 | 1163 |
|
1160 | 1164 |
str_ = 'CREATE TABLE '+table.to_str(db)+' (\n' |
1161 |
str_ += '\n, '.join(v.to_str(db) for v in cols)
|
|
1165 |
str_ += '\n, '.join(c.to_str(db) for c in cols)
|
|
1162 | 1166 |
str_ += '\n);\n' |
1163 | 1167 |
run_query(db, str_, cacheable=True, log_level=2) |
1164 | 1168 |
|
Also available in: Unified diff
sql.py: create_table(): Support LIKE table