Fix Python – Connecting to Microsoft SQL server using Python

I am trying to connect to SQL through python to run some queries on some SQL databases on Microsoft SQL server. From my research online and on this forum the most promising library seems to be pyodbc. So I have made the following code
import pyodbc
conn = pyodbc.connect(init_string=”driver={SQLOLEDB}; server=+ServerName+;

Fix Python – Python SQL query string formatting

I’m trying to find the best way to format an sql query string. When I’m debugging
my application I’d like to log to file all the sql query strings, and it is
important that the string is properly formated.
Option 1
def myquery():
sql = “select field1, field2, field3, field4 from table where condition1=1 and condition2=2”
con =….

Fix Python – How to log all sql queries in Django?

How can I log all SQL queries that my django application performed?
I want to log everything, including SQLs from admin site. I saw this question and a FAQ answer but I still can’t figure out where should I put
from django.db import connection

to log everything to one file?
So my question is – what should I do to have a file (….

Fix Python – SQLAlchemy: how to filter date field?

Here is model:
class User(Base):

birthday = Column(Date, index=True) #in database it’s like ‘1987-01-17’

I want to filter between two dates, for example to choose all users in interval 18-30 years.
How to implement it with SQLAlchemy?
I think of:
query = DBSession.query(User).filter(
and_(User.birthday >= ‘1988-01-17’, U….

Fix Python – How do I get a raw, compiled SQL query from a SQLAlchemy expression?

I have a SQLAlchemy query object and want to get the text of the compiled SQL statement, with all its parameters bound (e.g. no %s or other variables waiting to be bound by the statement compiler or MySQLdb dialect engine, etc).
Calling str() on the query reveals something like this:
SELECT id WHERE date_added <= %s AND date_added >= %s ORDER BY c….

Fix Python – How can I get dict from sqlite query?

db = sqlite.connect(“test.sqlite”)
res = db.execute(“select * from table”)

With iteration I get lists coresponding to the rows.
for row in res:
print row

I can get name of the columns
col_name_list = [tuple[0] for tuple in res.description]

But is there some function or setting to get dictionaries instead of list?
{‘col1’: ‘value’, ‘col2’: ‘….

Fix Python – django test app error – Got an error creating the test database: permission denied to create database

When I try to test any app with command (I noticed it when I tried to deploy myproject using fabric, which uses this command):
python test appname

I get this error:
Creating test database for alias ‘default’…
Got an error creating the test database: permission denied to create database

Type ‘yes’ if you would like to try deleting the….