Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved PostgreSQL support #29

Merged
merged 5 commits into from
Jul 8, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cs50/sql.py
Original file line number Diff line number Diff line change
@@ -122,20 +122,20 @@ def process(value):
self.logger.debug(statement)

# if SELECT (or INSERT with RETURNING), return result set as list of dict objects
if re.search(r"^\s*SELECT\s+", statement, re.I):
if re.search(r"^\s*SELECT", statement, re.I):
rows = result.fetchall()
return [dict(row) for row in rows]

# if INSERT, return primary key value for a newly inserted row
elif re.search(r"^\s*INSERT\s+", statement, re.I):
elif re.search(r"^\s*INSERT", statement, re.I):
if self.engine.url.get_backend_name() in ["postgres", "postgresql"]:
result = self.engine.execute(sqlalchemy.text("SELECT LASTVAL()"))
return result.first()[0]
else:
return result.lastrowid

# if DELETE or UPDATE, return number of rows matched
elif re.search(r"^\s*(?:DELETE|UPDATE)\s+", statement, re.I):
elif re.search(r"^\s*(?:DELETE|UPDATE)", statement, re.I):
return result.rowcount

# if some other statement, return True unless exception