• R/O
  • SSH

execsql: 提交

Default repository for execsql.py


Commit MetaInfo

修訂defa92d3cbb61ea4b2d7145f0043b21ad6bc1cc3 (tree)
時間2016-08-09 13:38:24
作者Dreas Nielsen <dreas.nielsen@gmai...>
CommiterDreas Nielsen

Log Message

Completed IMPORT routine for Excel.

Change Summary

差異

diff -r 964e063fe52b -r defa92d3cbb6 doc/execsql.htm
--- a/doc/execsql.htm Mon Aug 08 16:56:14 2016 -0700
+++ b/doc/execsql.htm Mon Aug 08 21:38:24 2016 -0700
@@ -6,7 +6,7 @@
66 <meta name="description" content="Documentation for execsql.py, a scripting client for PostgreSQL, SQL Server, MS-Access, SQLite, MariaDB, MySQL, and Firebird databases." />
77 <meta name="author" content="R. Dreas Nielsen" />
88 <meta name="created" content="2008-04-27" />
9-<meta name="revised" content="2016-08-05" />
9+<meta name="revised" content="2016-08-08" />
1010 <meta name="copyright" content="Copyright (c) 2015, 2016, R. Dreas Nielsen" />
1111 <style type="text/css">
1212 html, body {
@@ -585,6 +585,7 @@
585585 and <a href="http://sourceforge.net/projects/pywin32/">pywin32</a>.</li>
586586 <li>DSN data source: <a href="https://pypi.python.org/pypi/pyodbc/">pydobc</a>.</li>
587587 <li><a href="http://www.opendocumentformat.org/">OpenDocument</a> spreadsheets: <a href="https://pypi.python.org/pypi/odfpy/">odfpy</a>.</li>
588+ <li>Excel spreadsheets (read only): <a href="https://pypi.python.org/pypi/xlrd">xlrd</a>.</li>
588589 </ul>
589590 <p class="initial">Connections to SQLite databases are made using Python's standard library, so no
590591 additional software is needed.</p>
@@ -2254,6 +2255,11 @@
22542255 SHEET &lt;sheet_name&gt;
22552256 </div>
22562257
2258+<p class="initial">The syntax for importing data from an Excel spreadsheet is:</p>
2259+<div class="code">IMPORT TO [NEW|REPLACEMENT] &lt;table_name&gt; FROM EXCEL &lt;file_name&gt;
2260+ SHEET &lt;sheet_name&gt;
2261+</div>
2262+
22572263 <p class="initial"> Column names and column order in the input must exactly match those in the target table.
22582264 The column names in the input must also be valid for the DBMS in use.</p>
22592265
diff -r 964e063fe52b -r defa92d3cbb6 execsql/execsql.py
--- a/execsql/execsql.py Mon Aug 08 16:56:14 2016 -0700
+++ b/execsql/execsql.py Mon Aug 08 21:38:24 2016 -0700
@@ -887,13 +887,26 @@
887887 else:
888888 d = [cell for cell in cells]
889889 datarow = []
890- for c in range(len(d)):
890+ for c in d:
891891 if c.ctype == 0:
892892 # empty
893893 datarow.append(None)
894+ elif c.ctype == 1:
895+ # This might be a timestamp with time zone that xlrd treats as a string.
896+ try:
897+ dt = DT_TimestampTZ()._from_data(c.value)
898+ datarow.append(dt)
899+ except:
900+ datarow.append(c.value)
894901 elif c.ctype == 3 :
895902 # date
896- datarow.append(datetime.datetime(xlrd.xldate_as_tuple(c.value, self.datemode)))
903+ dt = xlrd.xldate_as_tuple(c.value, self.datemode)
904+ # Convert to time or datetime
905+ if not any(dt[:3]):
906+ # No date values
907+ datarow.append(datetime.time(*dt[3:]))
908+ else:
909+ datarow.append(datetime.datetime(*dt))
897910 elif c.ctype == 4:
898911 # Boolean
899912 datarow.append(bool(c.value))
@@ -7406,7 +7419,7 @@
74067419 try:
74077420 alldata = wbk.sheet_data(sheetname)
74087421 except:
7409- raise ErrInfo(type="cmd", other_msg="%s is not a worksheet in %s." % (sheetname, filename))
7422+ raise ErrInfo(type="cmd", other_msg="Error reading worksheet %s from %s." % (sheetname, filename))
74107423 return alldata[0], alldata[1:]
74117424
74127425
Show on old repository browser