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

Incorrect SQL generated #62

Closed
mariusmuja opened this issue Dec 23, 2015 · 3 comments
Closed

Incorrect SQL generated #62

mariusmuja opened this issue Dec 23, 2015 · 3 comments
Labels

Comments

@mariusmuja
Copy link

The following code:

    case class Person(id: Int, name: String, age: Int)
    case class Contact(id: Int, personId: Int, phone: String)

    val q = quote {
      (for {
        p <- query[Person] if(p.id == 999)
        c <- query[Contact] if(c.personId == p.id)
      } yield c).take(10)
    }

    db.run(q)

generates this SQL query:

SELECT c.id, c.person_id, c.phone FROM (SELECT id, personId, phone FROM person p, contact c WHERE (p.id = 999) AND (c.person_id = p.id)) c LIMIT 10

which contains two errors:

  • the id column in the inner select is ambiguous
  • the personId column in the inner select should be person_id (using SnakeCase)
@fwbrasil
Copy link
Collaborator

The fix for this issue is also available. Please let me know if it works with 0.1.4-SNAPSHOT.

@mariusmuja
Copy link
Author

Confirming that the fix works in 0.1.4-SNAPSHOT, thanks.

@mariusmuja
Copy link
Author

I noticed another issue: if a single field is selected, the query is not correct:

   case class Person(id: Int, name: String, age: Int)
    case class Contact(id: Int, personId: Int, phone: String)


    val q = quote {
      (for {
        p <- query[Person] if(p.id == 999)
        c <- query[Contact] if(c.personId == p.id)
      } yield c.id
      ).take(10)
    }

    db.run(q)

The generated query is:

SELECT c FROM (SELECT c.id FROM person p, contact c WHERE (p.id = 999) AND (c.person_id = p.id)) c LIMIT 10

The outer select should be c.id, not c.

@fwbrasil fwbrasil reopened this Dec 24, 2015
fwbrasil added a commit that referenced this issue Dec 24, 2015
jilen pushed a commit that referenced this issue Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants