Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
Quotes column names, handles selecting from tables with 0 rows.
Browse files Browse the repository at this point in the history
  • Loading branch information
vegitron committed Jun 30, 2015
1 parent 3470c09 commit 619f43d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sqlshare_rest/backend/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ def make_unique_name(name, existing):
column_name = make_unique_name(column_name, existing_column_names)
existing_column_names[column_name] = True

column_name = "[%s]" % (column_name)

if (col_type == float_type) or (col_type == decimal_type):
if null_ok:
column_defs.append("%s FLOAT" % column_name)
Expand Down Expand Up @@ -434,10 +436,14 @@ def create_table_from_query_result(self, name, source_cursor):

full_name = "[%s].[%s]" % (QUERY_SCHEMA, name)
create_table = "CREATE TABLE %s (%s)" % (full_name, column_def)

cursor.execute(create_table)

row = source_cursor.fetchone()

if row is None:
return 0

placeholders = ", ".join(list(map(lambda x: "?", row)))
insert = "INSERT INTO %s VALUES (%s)" % (full_name, placeholders)
row_count = 0
Expand Down

0 comments on commit 619f43d

Please sign in to comment.