Changes between Initial Version and Version 1 of Ticket #13321, comment 4


Ignore:
Timestamp:
Mar 28, 2019, 1:56:00 PM (5 years ago)
Author:
Jun Omae
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #13321, comment 4

    initial v1  
    66{{{#!diff
    77diff --git a/timingandestimationplugin/branches/trac1.0-Permissions/timingandestimationplugin/dbhelper.py b/timingandestimationplugin/branches/trac1.0-Permissions/timingandestimationplugin/dbhelper.py
    8 index 362ce21ab..fab89e614 100644
     8index 362ce21ab..7422d27a6 100644
    99--- a/timingandestimationplugin/branches/trac1.0-Permissions/timingandestimationplugin/dbhelper.py
    1010+++ b/timingandestimationplugin/branches/trac1.0-Permissions/timingandestimationplugin/dbhelper.py
     
    2323         try:
    2424             cur = db.cursor()
    25 @@ -118,17 +119,23 @@ def _prep_schema(s):
     25@@ -118,17 +119,22 @@ def _prep_schema(s):
    2626                      for i in s.split(',')))
    2727
    2828 def db_table_exists(env,  table):
    2929-    cnt = 0
     30-    with env.db_query as db:
     31-        if is_db_type(db, SqliteCon):
     32-            sql = "select count(*) from sqlite_master where type = 'table' and name = %s"
     33-            cnt = get_scalar(env, sql, 0, table)
     34-        else:
     35-            sql = """SELECT count(*) FROM information_schema.tables
     36-                     WHERE table_name = %%s and table_schema in (%s)
     37-                  """ % _prep_schema(current_schema(env))
     38-            cnt = get_scalar(env, sql, 0, table)
     39-    return cnt
    3040+    connection_uri = DatabaseManager(env).connection_uri
    3141+    if connection_uri.startswith('sqlite:'):
     
    4252+    else:
    4353+        raise NotImplementedError()
    44      with env.db_query as db:
    45 -        if is_db_type(db, SqliteCon):
    46 -            sql = "select count(*) from sqlite_master where type = 'table' and name = %s"
    47 -            cnt = get_scalar(env, sql, 0, table)
    48 -        else:
    49 -            sql = """SELECT count(*) FROM information_schema.tables
    50 -                     WHERE table_name = %%s and table_schema in (%s)
    51 -                  """ % _prep_schema(current_schema(env))
    52 -            cnt = get_scalar(env, sql, 0, table)
    53 -    return cnt
    54 +        rows = db(sql, [table])
    55 +        return rows[0][0]
     54+    rows = env.db_query(sql, [table])
     55+    return rows[0][0]
    5656
    5757 def get_column_as_list(env, sql, col=0, *params):