ruby on rails - Does ActiveRecord::Base.connection.execute only execute a single statement at a time? -
I have a bunch of SQL statements to execute on a database (I'm doing things that are used by rail methods Does not provide, as far as I know: creating ideas, adding foreign keys etc. It is mostly for non-rail interaction with data.) In short, I have the following:
Sql = "statement_1; statement_2; statement; ;;;;; ActiveRecord :: Base.connection.execute (sql)
or with new lines, such as:
sql =
(Clearly, these statements were kept in holders only , But according to my tests, I do not accept their content.)
In any case, only the first statement is executed and the other people are not given attention. What is happening? Even if I try more than one at a time, then I only see the effect of the first statement. Or do I need to execute each one separately? A set of statements is coming from a file, so it would be good to just load and execute the contents of the file. If I can adopt better strategies, then I will be interested in it.
I expected that it would shed some light, but besides using singular ("statement"), it is not. Perhaps due to the database engine I am using? (For reference, I am using SQLite at this time.)
Update: I am writing a method that does the following:
DRF Extract_SCL_Statements (SKL) Statement = [] SQLSplit (';'). Each dots statement. Statement.strip! Until the statement.empty? Statement + = '; Statement & lt; & Lt; Loop the statement end and return statement end
... and then on statements
. This problem has been fixed, but if there are more elegant solutions, then I want to hear about them.
If you look at the rail code, you will know that the executed method runs SQL, Therefore, it should run all of its questions till they are ';' Separate and valid
EDIT: Sorry! No, because it will add ';' Complain about the wrong syntax between your query string and
Comments
Post a Comment