10000 fix(db_api): revert Mutations API usage by IlyaFaer · Pull Request #285 · googleapis/python-spanner · GitHub
[go: up one dir, main page]

Skip to content
8000

fix(db_api): revert Mutations API usage #285

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

Merged
merged 2 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 15 additions & 8000 11 deletions google/cloud/spanner_dbapi/parse_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ def parse_insert(insert_sql, params):
Params: ['a', 'b', 'c', 'd']
it produces:
{
'homogenous': True,
'table': 'T',
'columns': ['f1', 'f2'],
'values': [('a', 'b',), ('c', 'd',)],
'sql_params_list': [
('INSERT INTO T (f1, f2) VALUES (%s, %s)', ('a', 'b')),
('INSERT INTO T (f1, f2) VALUES (%s, %s)', ('c', 'd'))
],
}

Case d)
Expand All @@ -249,7 +249,7 @@ def parse_insert(insert_sql, params):
it produces:
{
'sql_params_list': [
('INSERT INTO T (f1, f2) VALUES (%s, LOWER(%s))', ('a', 'b',))
('INSERT INTO T (f1, f2) VALUES (%s, LOWER(%s))', ('a', 'b',)),
('INSERT INTO T (f1, f2) VALUES (UPPER(%s), %s)', ('c', 'd',))
],
}
8000 Expand Down Expand Up @@ -306,15 +306,19 @@ def parse_insert(insert_sql, params):
# Case c)

columns = [mi.strip(" `") for mi in match.group("columns").split(",")]
sql_params_list = []
insert_sql_preamble = "INSERT INTO %s (%s) VALUES %s" % (
match.group("table_name"),
match.group("columns"),
values.argv[0],
)
values_pyformat = [str(arg) for arg in values.argv]
rows_list = rows_for_insert_or_update(columns, params, values_pyformat)
insert_sql_preamble = sanitize_literals_for_upload(insert_sql_preamble)
for row in rows_list:
sql_params_list.append((insert_sql_preamble, row))

return {
"homogenous": True,
"table": match.group("table_name"),
"columns": columns,
"values": rows_list,
}
return {"sql_params_list": sql_params_list}

# Case d)
# insert_sql is of the form:
Expand Down
48 changes: 31 additions & 17 deletions tests/unit/spanner_dbapi/test_parse_utils.py
8000 8305
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,32 @@ def test_parse_insert(self):
"INSERT INTO django_migrations (app, name, applied) VALUES (%s, %s, %s)",
[1, 2, 3, 4, 5, 6],
{
"homogenous": True,
"table": "django_migrations",
"columns": ["app", "name", "applied"],
"values": [(1, 2, 3), (4, 5, 6)],
"sql_params_list": [
(
"INSERT INTO django_migrations (app, name, applied) VALUES (%s, %s, %s)",
(1, 2, 3),
),
(
"INSERT INTO django_migrations (app, name, applied) VALUES (%s, %s, %s)",
(4, 5, 6),
),
]
},
),
(
"INSERT INTO django_migrations(app, name, applied) VALUES (%s, %s, %s)",
[1, 2, 3, 4, 5, 6],
{
"homogenous": True,
"table": "django_migrations",
"columns": ["app", "name", "applied"],
"values": [(1, 2, 3), (4, 5, 6)],
"sql_params_list": [
(
"INSERT INTO django_migrations (app, name, applied) VALUES (%s, %s, %s)",
(1, 2, 3),
),
(
"INSERT INTO django_migrations (app, name, applied) VALUES (%s, %s, %s)",
(4, 5, 6),
),
]
},
),
(
Expand All @@ -106,23 +118,25 @@ def test_parse_insert(self):
),
(
"INSERT INTO ap (n, ct, cn) "
"VALUES (%s, %s, %s), (%s, %s, %s), (%s, %s, %s),(%s,%s, %s)",
"VALUES (%s, %s, %s), (%s, %s, %s), (%s, %s, %s),(%s, %s, %s)",
(1, 2, 3, 4, 5, 6, 7, 8, 9),
{
"homogenous": True,
"table": "ap",
"columns": ["n", "ct", "cn"],
"values": [(1, 2, 3), (4, 5, 6), (7, 8, 9)],
"sql_params_list": [
("INSERT INTO ap (n, ct, cn) VALUES (%s, %s, %s)", (1, 2, 3)),
("INSERT INTO ap (n, ct, cn) VALUES (%s, %s, %s)", (4, 5, 6)),
("INSERT INTO ap (n, ct, cn) VALUES (%s, %s, %s)", (7, 8, 9)),
]
},
),
(
"INSERT INTO `no` (`yes`) VALUES (%s)",
(1, 4, 5),
{
"homogenous": True,
"table": "`no`",
"columns": ["yes"],
"values": [(1,), (4,), (5,)],
"sql_params_list": [
("INSERT INTO `no` (`yes`) VALUES (%s)", (1,)),
("INSERT INTO `no` (`yes`) VALUES (%s)", (4,)),
("INSERT INTO `no` (`yes`) VALUES (%s)", (5,)),
]
},
),
(
Expand Down
0