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

SqlKata generating query with unfulfilled parameters #62

Closed
cozyGalvinism opened this issue Apr 13, 2018 · 4 comments
Closed

SqlKata generating query with unfulfilled parameters #62

cozyGalvinism opened this issue Apr 13, 2018 · 4 comments

Comments

@cozyGalvinism
Copy link

I have the following Dictionary<string, object> called datensaetze:

Key Value
categoryID 5
customergroupID 1

Compiling this into a query:

                    var query = new Query(quelle.Tabelle).AsInsert(datensaetze);
                    var compiler = new MySqlCompiler();
                    var qStr = compiler.Compile(query).Sql;

results in the following query:

INSERT INTO `s_categories_avoid_customergroups` (`categoryID`, `customergroupID`) VALUES (@p0, @p1)

which is not executable. I can't use the QueryFactory, because I need the SQL string logged in a log file and possibly edited (see #60 )

@cozyGalvinism
Copy link
Author

cozyGalvinism commented Apr 13, 2018

I just saw, that the RawSql parameter contains

INSERT INTO `s_categories_avoid_customergroups` (`categoryID`, `customergroupID`) VALUES (?, ?)

though I'm still confused as to why, since I'm passing the dictionary, expecting the wildcards to be replaced with the actual values I set.

@ahmad-moussawi
Copy link
Contributor

This what is called parameters bindings, which is recommended to execute queries, for debugging purposes you can use the compiler.Compile(query).ToString()

Check https://stackoverflow.com/a/4712113/1104402 for more info

@cozyGalvinism
Copy link
Author

Well, I know parameterized queries, though I'm confused as to why the values aren't included in the query by the get-go.

Maybe as a feature request, you could have a parameter, which has the values in the query right away, properly escaped (maybe like SqlFull), so you aren't forced to use parameterized queries.

@ahmad-moussawi
Copy link
Contributor

thanks for your suggestion, but including the values directly in the generated sql open the door for unsecure/un-efficient code, this is why I am against this approach

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

No branches or pull requests

2 participants