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

Executing raw SQL directly through the connection #428

Open
crimson-knight opened this issue Nov 28, 2022 · 5 comments
Open

Executing raw SQL directly through the connection #428

crimson-knight opened this issue Nov 28, 2022 · 5 comments
Labels

Comments

@crimson-knight
Copy link
Contributor

I'm trying to figure out how I can run a LOAD DATA LOCAL INFILE command for MySQL directly over the default adapter connection.

I've tried a few that I found, but I get an error about "This command is not supported in the prepared statement protocol yet", so I'm guessing the methods I found are not executing the raw SQL string I'm providing.

Is there a way I can send SQL directly to the db over the connection?

@imdrasil
Copy link
Owner

Technically you always can get access to the adapter and execute whatever is supported by the driver - Jennifer::Adapter.default_adapter.exec. Also you can get access to a real connection going even further Jennifer::Adapter.default_adapter.db. I haven't tried this so can't say for sure - maybe this command can't be executed using prepared statement which is used by default. In this case the second me example should give you maximum flexibility crystal-db has right now

@crimson-knight
Copy link
Contributor Author

I was able to get what I needed to work by using the command literal. The load from file commands do not work with prepared statements, so that was a challenge to figure out.

Would it be worth adding a method that allows easier access or documenting how to execute SQL statements directly? Something that goes right on the model and passes down to the Jennifer::Adapter.default_adapter.db or whichever adapter someone has configured for their connections.

@imdrasil
Copy link
Owner

What do you mean under "execute SQL statement directly"? To enforce unprepared statement instead of prepared for custom SQL query?

@crimson-knight
Copy link
Contributor Author

Yes that's exactly what I mean

@imdrasil
Copy link
Owner

I will experiment with this

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