-
Notifications
You must be signed in to change notification settings - Fork 34
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
Escape column name #168
base: develop
Are you sure you want to change the base?
Escape column name #168
Changes from 13 commits
463368b
dd67ee1
363d225
9c677bc
12cf790
44af681
5638632
31e113d
146c0ab
63a14f5
efe9499
bec9c0f
502e34e
5ebf1d3
fc6ade8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ import norm/[model, postgres, types] | |
|
||
import ../models | ||
|
||
|
||
const | ||
dbHost = "postgres" | ||
dbUser = "postgres" | ||
|
@@ -33,7 +32,7 @@ suite "Import dbTypes from norm/private/postgres/dbtypes": | |
|
||
test "dbValue[DateTime] is imported": | ||
let users = @[newUser()].dup: | ||
dbConn.select("""lastLogin <= $1""", ?now()) | ||
dbConn.select(""""lastLogin" <= $1""", ?now()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An example for suddenly required quotation marks, this time not on an FK field as lastLogin is of type DateTime. Not sure what that is about. |
||
|
||
check len(users) == 0 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import std/[unittest, times, strutils] | ||
import std/[unittest, times, strutils, logging] | ||
|
||
import norm/[model, postgres] | ||
|
||
import ../models | ||
|
||
addHandler(newConsoleLogger(levelThreshold = lvlDebug)) | ||
|
||
|
||
const | ||
dbHost = "postgres" | ||
|
@@ -41,8 +43,8 @@ suite "``fk`` pragma": | |
check customer.id > 0 | ||
|
||
let | ||
userRows = dbConn.getAllRows(sql"""SELECT lastLogin, id FROM "User"""") | ||
customerRows = dbConn.getAllRows(sql"""SELECT userId, email, id FROM "Customer"""") | ||
userRows = dbConn.getAllRows(sql"""SELECT "lastLogin", "id" FROM "User" """) | ||
customerRows = dbConn.getAllRows(sql"""SELECT "userId", "email", "id" FROM "Customer" """) | ||
|
||
check userRows.len == 1 | ||
check userRows[0][1] == ?user.id | ||
|
@@ -70,6 +72,6 @@ suite "``fk`` pragma": | |
for inpCustomer in inpCustomers.mitems: | ||
dbConn.insert inpCustomer | ||
|
||
dbConn.select(outCustomers, """"userid" = $1""", userA.id) | ||
dbConn.select(outCustomers, """"userId" = $1""", userA.id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An example for sudden case-sensitivity, though that is when comparing column names and not during actual queries, not sure how much that matters. |
||
|
||
check outCustomers === inpCustomers[0..^2] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import std/[unittest, with, strutils, sugar, options] | ||
|
||
|
||
import norm/[model, postgres] | ||
|
||
import ../models | ||
|
@@ -67,7 +68,7 @@ suite "Row CRUD": | |
|
||
let | ||
personRows = dbConn.getAllRows(sql"""SELECT name, pet, id FROM "Person"""") | ||
petRows = dbConn.getAllRows(sql"""SELECT species, favToy, id FROM "Pet"""") | ||
petRows = dbConn.getAllRows(sql"""SELECT species, "favToy", id FROM "Pet"""") | ||
toyRows = dbConn.getAllRows(sql"""SELECT price, id FROM "Toy"""") | ||
|
||
check personRows.len == 1 | ||
|
@@ -219,7 +220,7 @@ suite "Row CRUD": | |
|
||
let | ||
personRow = get dbConn.getRow(sql"""SELECT name, pet, id FROM "Person" WHERE id = $1""", person.id) | ||
petRow = get dbConn.getRow(sql"""SELECT species, favToy, id FROM "Pet" WHERE id = $1""", pet.id) | ||
petRow = get dbConn.getRow(sql"""SELECT species, "favToy", id FROM "Pet" WHERE id = $1""", pet.id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An example for suddenly required quotation marks, necessary only on the FK field "favToy", not on the others. Same for Line 71 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if you put the rest in quotations for consistency? Does it break the test? This is so weird 🤔 Possibly, this has to do with mixing cases. If the column name uses mixed case, it must be quoted. But that's just a wild guess. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing the line to this: An observation I made though, is that this: I'm getting the impression that not only are suddenly the quotation marks sometimes mandatory, they cause the column names to suddenly be case-sensitive. |
||
toyRow = get dbConn.getRow(sql"""SELECT price, id FROM "Toy" WHERE id = $1""", pet.favToy.id) | ||
|
||
check personRow == @[?"Bob", ?pet.id, ?person.id] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ suite "Table creation": | |
|
||
check dbConn.getAllRows(qry, "FurnitureTable") == @[ | ||
@[?"id", ?"bigint"], | ||
@[?"legcount", ?dftDbInt] | ||
@[?"legCount", ?dftDbInt] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An example for sudden case-sensitivity, though that is when comparing column names and not during actual queries, not sure how much that matters. |
||
] | ||
|
||
test "Create tables": | ||
|
@@ -80,7 +80,7 @@ suite "Table creation": | |
] | ||
|
||
check dbConn.getAllRows(qry, "Pet") == @[ | ||
@[?"favtoy", ?"bigint"], | ||
@[?"favToy", ?"bigint"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An example for sudden case-sensitivity, though that is when comparing column names and not during actual queries, not sure how much that matters. |
||
@[?"id", ?"bigint"], | ||
@[?"species", ?"text"] | ||
] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add quotation marks here because otherwise the FK constraints wouldn't have any.
Please note that I ONLY added the quotation marks in these two lines.
There is a third line dealing with FK constraints, line 107 further up, where I DID NOT add quotation marks around the field, because when that line gets called by tests the field suddenly already has quotationmarks (possibly because it calls the col proc where the others don't).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oof, that's dangerous behavior. col proc should be called always.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tried it, replacing
fld
on there withobj.col(fld)
does work.I'm not sure if the code that generates is correct, as stated I haven't read through this code in any intensity in order to understand what's going on, but it does pass the tests.