I need to execute this query to find out the next auto_increment value that will be used by MySQL for a particular table.
find_by_sql ["select auto_increment from information_schema.tables where
table_schema = ? and table_name = ? and auto_increment is not null", db_name, tbl_name]
How to invoke this particular query? This works on any model that I invoke it with returning an array of size 1 containing the object of the model. Edit: The object contains a hash named attributes which contains the auto_increment value as desired.
Are there any other ways to run such generic queries ? Would like to know if a change in the whole approach of using find_by_sql is possible to solve the original problem as well.
If you want to run raw SQL without involving a model, you can obtain the
connectiondirectly and call one of theselect_*methods (select_valuein this case). These methods just take a SQL statement as a string, so you can callsanitize_sql_arrayto transform your parameters array (note thatsanitize_sql_arrayis protected, sosendmay be required).The result returned will be a string.