Python django.conf.settings.DATABASE_ENGINE Examples
The following are 3
code examples of django.conf.settings.DATABASE_ENGINE().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.conf.settings
, or try the search function
.
Example #1
Source File: sql.py From canvas with BSD 3-Clause "New" or "Revised" License | 6 votes |
def content(self): width_ratio_tally = 0 for query in self._queries: query['sql'] = reformat_sql(query['sql']) try: query['width_ratio'] = (query['duration'] / self._sql_time) * 100 except ZeroDivisionError: query['width_ratio'] = 0 query['start_offset'] = width_ratio_tally width_ratio_tally += query['width_ratio'] context = self.context.copy() context.update({ 'queries': self._queries, 'sql_time': self._sql_time, 'is_mysql': settings.DATABASE_ENGINE == 'mysql', }) return render_to_string('debug_toolbar/panels/sql.html', context)
Example #2
Source File: __main__.py From ara with GNU General Public License v3.0 | 5 votes |
def main(): os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ara.server.settings") try: from django.core.management import execute_from_command_line except ImportError as e: raise MissingDjangoException from e # Validate that the settings file exists and is readable before bootstrapping if not os.path.exists(settings.ARA_SETTINGS): print("[ara] Unable to access or read settings file: %s" % settings.ARA_SETTINGS) raise MissingSettingsException print("[ara] Using settings file: %s" % settings.ARA_SETTINGS) if settings.DATABASE_ENGINE == "django.db.backends.postgresql": try: import psycopg2 # noqa except ImportError as e: raise MissingPsycopgException from e if settings.DATABASE_ENGINE == "django.db.backends.mysql": try: import MySQLdb # noqa except ImportError as e: raise MissingMysqlclientException from e execute_from_command_line(sys.argv)
Example #3
Source File: views.py From canvas with BSD 3-Clause "New" or "Revised" License | 5 votes |
def sql_explain(request): """ Returns the output of the SQL EXPLAIN on the given query. Expected GET variables: sql: urlencoded sql with positional arguments params: JSON encoded parameter values duration: time for SQL to execute passed in from toolbar just for redisplay hash: the hash of (secret + sql + params) for tamper checking """ from debug_toolbar.panels.sql import reformat_sql sql = request.GET.get('sql', '') params = request.GET.get('params', '') hash = sha_constructor(settings.SECRET_KEY + sql + params).hexdigest() if hash != request.GET.get('hash', ''): return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert if sql.lower().strip().startswith('select'): params = simplejson.loads(params) cursor = connection.cursor() if settings.DATABASE_ENGINE == "sqlite3": # SQLite's EXPLAIN dumps the low-level opcodes generated for a query; # EXPLAIN QUERY PLAN dumps a more human-readable summary # See http://www.sqlite.org/lang_explain.html for details cursor.execute("EXPLAIN QUERY PLAN %s" % (sql,), params) else: cursor.execute("EXPLAIN %s" % (sql,), params) headers = [d[0] for d in cursor.description] result = cursor.fetchall() cursor.close() context = { 'result': result, 'sql': reformat_sql(cursor.db.ops.last_executed_query(cursor, sql, params)), 'duration': request.GET.get('duration', 0.0), 'headers': headers, } return render_to_response('debug_toolbar/panels/sql_explain.html', context) raise InvalidSQLError("Only 'select' queries are allowed.")