ó ü¤Sc@sSdZddlZddlZddlZdefd„ƒYZedkrOndS(sf Created on Sep 7, 2011 @author: vieglais Import a Excel worksheet as tables in an SQLite database. iÿÿÿÿNtXls2SqlcBs_eZdZd d„Zd„Zdd„Zddd„Zd„Zdd„Z d d „Z RS( scUtility class that will import worksheets from an Excel workbook as tables in an SQL database. cCsXtjdƒ|_||_dg|_g|_|jdkrTtjdƒ|_ndS(s¤ Initialize the class. :param db: An open DB-API 2.0 database connection. If None then an in-memory SQLite3 database will be made. Rtnones:memory:N( tloggingt getLoggertlogtdbtRESERVEDtcolumnstNonetsqlite3tconnect(tselfR((ss/var/lib/jenkins/jobs/DataONE-Operations-Manual/workspace/operations/tools/docutils/rst_directives/utils/xls2sql.pyt__init__s    cCsðxé|jƒD]Û}d|}g}d}xe||dD]U}|d|jkr8|jd|d|dfƒ|jj|ƒ|d7}q8q8W|dj|ƒ7}|d 7}tjd |ƒ|jjƒ}|j |ƒ|jj ƒq Wd S( s˜Create a new table in the database using the column names contained in meta. meta is structured like:: meta = {name: {'start_row': 'columns': [{'name': column name, 'id': zero offset from left, 'type': sqlite type}, ...], }, } sCREATE TABLE %s (iRtnames%s %sttypeis, s);sCreate table SQL: %sN( tkeysRtappendRtjoinRtinfoRtcursortexecutetcommit(R tmetattnametsqltfieldstidxtcoltcn((ss/var/lib/jenkins/jobs/DataONE-Operations-Manual/workspace/operations/tools/docutils/rst_directives/utils/xls2sql.pyt createTables$s   icCsFi}x9|jƒD]+}|j|ƒ}|j||ƒ||tobjectRRG(((ss/var/lib/jenkins/jobs/DataONE-Operations-Manual/workspace/operations/tools/docutils/rst_directives/utils/xls2sql.pyts    ’