Created
December 8, 2013 13:43
-
-
Save hideshi/7857697 to your computer and use it in GitHub Desktop.
Script for making insert statement.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from sys import argv | |
f = open(argv[1], 'r') | |
table_name = f.readline().strip() | |
col_names = map(lambda x: x.strip(), f.readline().split(',')) | |
types = map(lambda x: x.strip(), f.readline().split(',')) | |
def func(t): | |
if t[1] == 's': | |
return (t[0], "'" + t[2] + "'") | |
else: | |
return (t[0], t[2]) | |
for line in f: | |
elems = map(func, zip(col_names, types, [elem.strip() for elem in line.split(',')])) | |
expr1 = 'INSERT INTO ' + table_name + ' (' | |
expr2 = 'VALUES (' | |
for col, val in elems: | |
expr1 += col + ',' | |
expr2 += val + ',' | |
expr1 = expr1.strip(',') + ')' | |
expr2 = expr2.strip(',') + ');' | |
print expr1, expr2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment