From 0a062ea8eaaba60730f3ff5b5ce6e8e2dc40d942 Mon Sep 17 00:00:00 2001 From: "bnmcgn@gmail.com" Date: Fri, 2 Jul 2021 10:45:43 -0700 Subject: [PATCH] Version 0.0.2 - Add code to handle varying marker chars in parameterized queries --- setup.py | 2 +- src/vibase.py | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index c23b0f6..7a47994 100755 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ author='Ben McGunigle', author_email='bnmcgn@gmail.com', 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': [ diff --git a/src/vibase.py b/src/vibase.py index 307f317..1183023 100644 --- a/src/vibase.py +++ b/src/vibase.py @@ -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() @@ -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: @@ -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 = []