Basic usage:
./pyxmdb.py -x -f EXPORT.csv -u USER -w PASSWORD -d DBNAME -b PYTHONDBMSMODULE -q "select * from TABLE"
./pyxmdb.py -i -f IMPORT.csv -u USER -w PASSWORD -d DBNAME -b PYTHONDBMSMODULE -q "insert into TABLE values (%s)"
Where:
EXPORT.csv and IMPORT.csv are comma delimited text files (excel format)
USER and PASSWORD are the user name and password required for you to connect to the DBMS
DBNAME is the name of the database
PYTHONDBMSMODULE is one of the supported Python DBMS modules defined in pyxmdb.py.cfg
TABLE is the name of the table in your database.
Note: export will take any valid select query, including those which involve more than one table.
import may require use of the "insert into TABLE (col2,col3,col5) values (%s)"
if IMPORT.csv doesn't match the structure of TABLE exactly.
Full list of command line paramters (by category):
-- MANDATORY --
(-i OR -x, if both specified then the last one will be used)
-i,--import = tells pyxmdb that you want to import data
-x,--export = tells pyxmdb that you want to export data
(-q/--sql OR --sqlfile, if both specified then -q/--sql will take priority)
-q,--sql = the select or insert statement to use for the export or import
--sqlfile = the file containing the select or insert statement to use for the export or import
(--dsn OR the minimal set of other database parameters required for the given DBMS. typically -u -w -d)
-s,--dsn = if the DBMS supports it, you can specify a single string with all
of the database parameters to use for connecting
-u,--dbuser = user name for the DB
-w,--dbpassword = password for the DB
-d,--dbname = name of the database to connect to
For Oracle, this is the SID, for SQLite it is the filename
(technically -f and -b are optional, but they are very highly recommended)
-f,--filename = name of the datafile to import from or export to (default is STDIN / STDOUT)
-b,--dbms = the Python DB module to load and use for the DB connection (default = sqlite3)
Note: the default can be changed in the config file pyxmdb.py.cfg in
"[dbms],default"
-- OPTIONAL --
Database:
-p,--dbport = port number to use for connecting to the DB
-v,--dbserver = IP or hostname of the DB server.
-c,--commitcount = number of rows to insert before issuing a COMMIT
-e,--errorcount = number of insert exceptions to tolerate before aborting the transaction
--header = if exporting, the column names will be written out as the first line of
the file if importing, the first line of the file will be skipped
--presql parameter for specifying an SQL command to run before the import/export
--postsql parameter for specifying an SQL command to run after the import/export
--presqlfile = the file containing the SQL command to run before the export/import
--postsqlfile = the file containing the SQL command to run after the export/import
Miscelaneous:
-n,--cfgfile = fully qualified name of the config file containing the logging and
DBMS configuration
-h,--help = displays this message
--bz2 = implies that the name given for --filename is a bzip2 compressed file
--gzip = implies that the name given for --filename is a gzip compressed file
Format: (refer to the docs for Python's "csv" module for details)
--quoting = how agressive the quoting should be.
--lineterminator = what character(s) to use for a new line (default is \r\n)
--skipinitialspace = should we skip leading spaces
--doublequote = if "quotechar" appears inside of a string that is itself quoted, how
should it be written
False = use "escapechar", True = double up (use two "quotechar")
--escapechar = character to use when escaping a quote
--quotechar = character to use in place of a single quote (default = ')
--delimiter = character to use for separating fields/columns in the text file
(default = ,)
--dialect = a csv dialect to use (default = excel)