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

cmp: EqLit may break the query #199

Open
mmatczuk opened this issue Oct 7, 2021 · 1 comment
Open

cmp: EqLit may break the query #199

mmatczuk opened this issue Oct 7, 2021 · 1 comment

Comments

@mmatczuk
Copy link
Contributor

mmatczuk commented Oct 7, 2021

There is a query builder code using the table model table.SchedRun.UpdateBuilder("status").If(qb.EqLit("status", "RUNNING")), it generates

AAA [query statement="UPDATE scheduler_task_run SET status=? WHERE cluster_id=? AND type=? AND task_id=? AND id=? IF status=RUNNING " values=[FOO 30f3ac8b-4f29-4beb-8b1d-d40020586a96 mock fe0e6697-ad19-47af-a359-8c2f8d7a4e0d eea3301d-275b-11ec-bf87-c85b76f42222] consistency=QUORUM]

Which fails with no viable alternative at input.
As it turns out the issue is the lack of quotes i.e. IF status='RUNNING'.
The workaround is by using EqNamed instead.

@izenhaim
Copy link
Contributor

izenhaim commented Jun 2, 2024

From what I have seen using this function, we must not use a single quote ( ' ) when the column type is UUID for an instance. I personally fixed my issue like this:

qb.EqLit("string_id", fmt.Sprintf("'%s'", stringid))

Since we can't have the column type in qb, I don't think there is any good way to fix this function. we could update the docs, or add a new function like

qb.EqLitStr that does like this:

func EqLitStr(column, literal string) Cmp {
	return Cmp{
		op:     eq,
		column: column,
		value:  litStr(literal),
	}
}
type litStr string

func (l litStr) writeCql(cql *bytes.Buffer) (names []string) {
	cql.WriteString("'")
	cql.WriteString(string(l))
	cql.WriteString("'")
	return nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants