• R/O
  • SSH

execsql: Commit

Default repository for execsql.py


Commit MetaInfo

Révisionb170da182a8892c67ce0c9bd6656ff3ca00d8508 (tree)
l'heure2020-02-09 02:35:20
AuteurDreas Nielsen <dnielsen@inte...>
CommiterDreas Nielsen

Message de Log

Made encoding for access controlled by a flag for Jet version.

Change Summary

Modification

diff -r 993b1fdb5d5b -r b170da182a88 execsql/execsql.py
--- a/execsql/execsql.py Thu Feb 06 17:10:26 2020 -0800
+++ b/execsql/execsql.py Sat Feb 08 09:35:20 2020 -0800
@@ -27,12 +27,12 @@
2727 #
2828 # ===============================================================================
2929
30-__version__ = "1.61.5"
31-__vdate = "2020-02-06"
30+__version__ = "1.61.7"
31+__vdate = "2020-02-08"
3232
3333 primary_vno = 1
3434 secondary_vno = 61
35-tertiary_vno = 5
35+tertiary_vno = 7
3636
3737 import os
3838 import os.path
@@ -3083,11 +3083,13 @@
30833083 class AccessDatabase(Database):
30843084 # Regex for the 'create temporary view' SQL extension
30853085 temp_rx = re.compile(r'^\s*create(?:\s+or\s+replace)?(\s+temp(?:orary)?)?\s+(?:(view|query))\s+(\w+) as\s+', re.I)
3086+ # Connection strings are a tuple, where the first part is the connection string and the second part is
3087+ # a flag indicating whether this driver uses Jet 4.
30863088 connection_strings = (
3087- "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=%s;ExtendedAnsiSQL=1;",
3088- "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=%s;",
3089- "Provider=Microsoft.ACE.OLEDB.15.0; Data Source=%s;",
3090- "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=%s;"
3089+ ("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=%s;ExtendedAnsiSQL=1;", True),
3090+ ("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=%s;", False),
3091+ ("Provider=Microsoft.ACE.OLEDB.15.0; Data Source=%s;", True),
3092+ ("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=%s;", True)
30913093 )
30923094 def __init__(self, Access_fn, need_passwd=False, user_name=None, encoding=None, password=None):
30933095 global pyodbc
@@ -3103,9 +3105,12 @@
31033105 self.type = dbt_access
31043106 self.server_name = None
31053107 self.db_name = Access_fn
3108+ # The following assignment is tentative and may be changed when the connection is made.
3109+ self.jet4 = len(Access_fn) > 6 and Access_fn.lower()[-6:] == '.accdb'
31063110 self.user = user_name
31073111 self.need_passwd = need_passwd
31083112 self.password = password
3113+ # Encoding is only applicable to Jet < 4.0: non-accdb databases.
31093114 self.encoding = encoding or 'windows_1252'
31103115 self.encode_commands = True
31113116 self.dao_conn = None
@@ -3132,7 +3137,7 @@
31323137 self.password = get_password("MS-Access", self.db_name, self.user)
31333138 connected = False
31343139 db_name = os.path.abspath(self.db_name)
3135- for cs in self.connection_strings:
3140+ for cs, jet4flag in self.connection_strings:
31363141 if self.need_passwd:
31373142 connstr = "%s Uid=%s; Pwd=%s;" % (cs % db_name, self.user, self.password)
31383143 else:
@@ -3143,6 +3148,7 @@
31433148 exec_log.log_status_info(u"Could not connect via ODBC using: %s" % connstr)
31443149 else:
31453150 exec_log.log_status_info(u"Connected via ODBC using: %s" % connstr)
3151+ self.jet4 = jet4flag
31463152 connected = True
31473153 break
31483154 if not connected:
@@ -3200,9 +3206,12 @@
32003206 def exec1(sql, paramlist):
32013207 tqd = self.temp_rx.match(sql)
32023208 if tqd:
3203- #qn = tqd.group(3).encode(self.encoding)
3204- qn = tqd.group(3)
3205- qsql = sql[tqd.end():].encode(self.encoding)
3209+ if self.jet4:
3210+ qn = tqd.group(3)
3211+ qsql = sql[tqd.end():]
3212+ else:
3213+ qn = tqd.group(3).encode(self.encoding)
3214+ qsql = sql[tqd.end():].encode(self.encoding)
32063215 if self.dao_conn is None:
32073216 self.open_dao()
32083217 try:
@@ -3221,17 +3230,24 @@
32213230 else:
32223231 self.dao_flush_check()
32233232 curs = self.cursor()
3224- encoded_sql = type(u"")(sql).encode(self.encoding)
3225- if sys.version_info < (3,):
3226- if paramlist is None:
3227- curs.execute(encoded_sql)
3228- else:
3229- curs.execute(encoded_sql, paramlist)
3233+ if self.jet4:
3234+ encoded_sql = type(u"")(sql)
32303235 else:
3231- if paramlist is None:
3232- curs.execute(encoded_sql.decode(self.encoding))
3233- else:
3234- curs.execute(encoded_sql.decode(self.encoding), paramlist)
3236+ encoded_sql = type(u"")(sql).encode(self.encoding)
3237+ if paramlist is None:
3238+ curs.execute(encoded_sql)
3239+ else:
3240+ curs.execute(encoded_sql, paramlist)
3241+ #if sys.version_info < (3,):
3242+ # if paramlist is None:
3243+ # curs.execute(encoded_sql)
3244+ # else:
3245+ # curs.execute(encoded_sql, paramlist)
3246+ #else:
3247+ # if paramlist is None:
3248+ # curs.execute(encoded_sql.decode(self.encoding))
3249+ # else:
3250+ # curs.execute(encoded_sql.decode(self.encoding), paramlist)
32353251 subvars.add_substitution("$LAST_ROWCOUNT", curs.rowcount)
32363252 if type(sqlcmd) in (list, tuple):
32373253 for sql in sqlcmd:
diff -r 993b1fdb5d5b -r b170da182a88 setup.py
--- a/setup.py Thu Feb 06 17:10:26 2020 -0800
+++ b/setup.py Sat Feb 08 09:35:20 2020 -0800
@@ -4,7 +4,7 @@
44 long_description = f.read()
55
66 setuptools.setup(name='execsql',
7- version='1.61.5',
7+ version='1.61.7',
88 description="Runs a SQL script against a PostgreSQL, MS-Access, SQLite, MS-SQL-Server, MySQL, MariaDB, Firebird, or Oracle database, or an ODBC DSN. Provides metacommands to import and export data, copy data between databases, conditionally execute SQL and metacommands, and dynamically alter SQL and metacommands with substitution variables. Data can be exported in 13 different formats, including CSV, TSV, ODS, HTML, JSON, LaTeX, and Markdown tables, and using custom templates.",
99 author='Dreas Nielsen',
1010 author_email='dreas.nielsen@gmail.com',
Afficher sur ancien navigateur de dépôt.