Skip to content

Commit

Permalink
Version 0.0.2
Browse files Browse the repository at this point in the history
- Add code to handle varying marker chars in parameterized queries
  • Loading branch information
BnMcGn committed Jul 2, 2021
1 parent 40de3c5 commit 0a062ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
author='Ben McGunigle',
author_email='[email protected]',
url='https://github.com/BnMcGn/vibase',
download_url='https://github.com/BnMcGn/vibase/archive/0.0.1.zip',
download_url='https://github.com/BnMcGn/vibase/archive/0.0.2.zip',
packages=['src'],
entry_points = {
'console_scripts': [
Expand Down
19 changes: 15 additions & 4 deletions src/vibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def extract_conn_from_module(module):
for x in module.__dict__.values():
if hasattr(x, "cursor"):
return x
raise (RuntimeError, "Couldn't find connection")

def write_csv(fname, conn, table):
cursor = conn.cursor()
Expand All @@ -38,10 +39,23 @@ def get_connection(args):
module = module[:-3]
elif module.endswith(".pyc"):
module = module[:-4]
return extract_conn_from_module(import_module(module))
conn = extract_conn_from_module(import_module(module))
configure_for_connection(conn)
return conn
else:
raise (RuntimeError, "No connection source supplied")

param_char = "?"
def sql_param_char():
return param_char

def configure_for_connection(conn):
global param_char
"Attempt to detect type of DB, and set up some options accordingly"
#FIXME: Better detection method?
if "psycopg2" in repr(type(conn)):
param_char = "%s"

def filter_changed_rows(refstream, editstream):
#Check the header row
try:
Expand Down Expand Up @@ -75,9 +89,6 @@ def decide_action(rows):
dels.append(ref)
return {'reference': refs, 'edit': edits, 'delete': dels}

def sql_param_char():
return "?"

def make_update_sql(table, headers, old_data, upd_data):
vclause = []
wclause = []
Expand Down

0 comments on commit 0a062ea

Please sign in to comment.