Skip to content

Commit 743a0ce

Browse files
committed
updates
1 parent 9b2f66e commit 743a0ce

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

csv2sql.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ def main(argv):
6161
header = None
6262
skipRows = 0
6363
ignoreColumns = None
64+
tableExists = False
6465

6566
try:
6667
opts, args = getopt.getopt(argv, "h:t:k:vq", \
67-
["help", "verbose", "quiet", "header=", "tablename=", "output=", "key=", "skip=", "ignore="])
68+
["help", "verbose", "quiet", "header=", "tablename=", "output=", "key=", "skip=", "ignore=", "tableexists"])
6869
except getopt.GetoptError:
6970
printError("Invalid argument error")
7071
printUsage()
@@ -88,15 +89,18 @@ def main(argv):
8889
skipRows = int(arg)
8990
elif opt in ("--ignore"):
9091
ignoreColumns = arg.split(",")
91-
92+
elif opt in ("--tableexists"):
93+
tableExists = True
94+
9295
# print args
9396
if len(args) != 1:
9497
printUsage()
9598
return 1
9699
input_filename = args[0]
97100

98101
printVerbose("csv2sql.py - Version %s - Run date: %s" % (__version__, time.ctime()) )
99-
printVerbose("Source file: %s - %d bytes - Stamped %s" % (os.path.basename(input_filename), os.path.getsize(input_filename), time.ctime(os.path.getmtime(input_filename))) )
102+
printVerbose("Source file: %s - %d bytes - Stamped %s" \
103+
% (os.path.basename(input_filename), os.path.getsize(input_filename), time.ctime(os.path.getmtime(input_filename))) )
100104
printVerbose("Skipping %d row(s)" % skipRows)
101105

102106
input = file(input_filename,'r')
@@ -119,7 +123,7 @@ def main(argv):
119123
printVerbose("Guessing Excel CSV")
120124
elif(tabs > commas):
121125
dialect = "excel-tab"
122-
printVerbose("Guess Excel TSV")
126+
printVerbose("Guessing Excel TSV")
123127

124128
# reset input file back to beginning
125129
input.seek(0)
@@ -130,7 +134,8 @@ def main(argv):
130134
for i in range(skipRows):
131135
c.next()
132136
printVerbose("Using header row: %s" % header)
133-
print createTable(header)
137+
if not tableExists:
138+
print createTable(header)
134139
print "\nbegin;\n"
135140
for row in c:
136141
print insertRow(row)

strip_nulls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def main(argv):
66
while data != "":
77
sys.stdout.write(data.replace("\0",""))
88
data = f.read(4096)
9-
9+
1010

1111
if __name__ == "__main__":
1212
sys.exit(main(sys.argv[1:])) # slice this filename off args

test/nulls.csv

9 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)