Spaces:
Sleeping
Sleeping
samarth upadhyay commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -93,7 +93,6 @@ def file_to_sql(file, filename):
|
|
| 93 |
create_stmt = f"CREATE TABLE {table_name} ({', '.join(cols)});\n"
|
| 94 |
|
| 95 |
# 5. Generate INSERT Statements
|
| 96 |
-
# Note: For very large files, bulk loading is better, but for "Sample" sizes, this is universally compatible
|
| 97 |
inserts = []
|
| 98 |
for _, row in df.iterrows():
|
| 99 |
vals = []
|
|
@@ -101,7 +100,9 @@ def file_to_sql(file, filename):
|
|
| 101 |
if pd.isna(v):
|
| 102 |
vals.append("NULL")
|
| 103 |
elif isinstance(v, str):
|
| 104 |
-
|
|
|
|
|
|
|
| 105 |
else:
|
| 106 |
vals.append(str(v))
|
| 107 |
inserts.append(f"INSERT INTO {table_name} VALUES ({', '.join(vals)});")
|
|
|
|
| 93 |
create_stmt = f"CREATE TABLE {table_name} ({', '.join(cols)});\n"
|
| 94 |
|
| 95 |
# 5. Generate INSERT Statements
|
|
|
|
| 96 |
inserts = []
|
| 97 |
for _, row in df.iterrows():
|
| 98 |
vals = []
|
|
|
|
| 100 |
if pd.isna(v):
|
| 101 |
vals.append("NULL")
|
| 102 |
elif isinstance(v, str):
|
| 103 |
+
# FIX: Handle nested quotes for Python < 3.12 by extracting variable
|
| 104 |
+
clean_v = str(v).replace("'", "''")
|
| 105 |
+
vals.append(f"'{clean_v}'")
|
| 106 |
else:
|
| 107 |
vals.append(str(v))
|
| 108 |
inserts.append(f"INSERT INTO {table_name} VALUES ({', '.join(vals)});")
|