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

Used with GORM resulting in errors for simple queries. May be relate to column name not lowercase #65

Closed
pkordes opened this issue Jul 18, 2022 · 6 comments · Fixed by #77

Comments

@pkordes
Copy link

pkordes commented Jul 18, 2022

result := db.First(&Request{}, "Token = ?", request.Token)

Results in: Syntax error near . " token"

@pkordes
Copy link
Author

pkordes commented Jul 18, 2022

using Postgres driver as instructed

@pkordes
Copy link
Author

pkordes commented Jul 18, 2022

Seems to actually be related to #62

@sneko
Copy link

sneko commented Jul 18, 2022

@pkordes could you post the raw SQL query your Gorm is doing? Would help knowing if it's linked to #62 or not.

Thank you,

@pkordes
Copy link
Author

pkordes commented Jul 18, 2022

I would if I knew how to see that. I dove into the GORM code and there isn't anywhere that it shows me the SQL it is creating. The reason that I believe it is related is that I removed the conditional above and it is explicitly giving a Syntax error on a quote " ... this leads me to believe it is the same issue. You can see my line of code where we are doing a .First function on the driver and supplying the request model that would be filled.

@pkordes
Copy link
Author

pkordes commented Jul 20, 2022

I managed to output the sql queries but it is still failing. I am happy to try and fix for you but I don't know how to break into a debugger for this code. stepping through my code it gets into GORM but not into your driver code.

SELECT * FROM "requests" WHERE Token = 'token1238' ORDER BY "requests"."token" LIMIT 1

  • attribute Token does not exist in table requests (it does and works fine with dockerized postgres)

SELECT * FROM "guard_rails" WHERE "guard_rails"."name" IN (NULL)

  • Syntax error near ( null )

SELECT * FROM "accounts" WHERE "accounts"."id" = '11223333' ORDER BY "accounts"."id" LIMIT 1

  • Error finding account id: 11223333 with error: Syntax error near ( null )

SELECT * FROM "requests" WHERE ID = '4cacb10dd' ORDER BY "requests"."token" LIMIT 1

  • attribute ID does not exist in table requests

These are just a few examples. Please tell me how to debug into the code and I can look into fixing

@pkordes
Copy link
Author

pkordes commented Jul 20, 2022

This was with the fix for #62.

@pkordes pkordes changed the title Used with GORM does not support WHERE conditionals Used with GORM resulting in errors for simple queries. May be relate to column name not lowercase Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants