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

rawQuery with rawAddPrefix - field name in the query, that containes the table name #1009

Open
putaprost opened this issue Jan 23, 2023 · 0 comments

Comments

@putaprost
Copy link

I don't think this can work. I found it best for me to remove rawAddPrefix function.
I had a longer query, and the preg_match_all gave me two identical table names.
In the loop it was run twice, so, for example i had, tbl_cars, and then tbl_tbl_cars.
I tried to use array unique on the $table array, and it was all ok, everything looked ok.
But then, i realized i had a field name in the query, that contained the table name, sometihng like cars_id.
And even with array unique on the $table array, i was getting SELECT tbl_cars.tbl_cars_id instead of tbl_cars.cars_id.
It can probably can be fixed, because i think you allways have a . (dot) before the column name, but i have no ideea what else can happend after this so i disabled this function.

If anyone needs it, it could work, if you are carefull and dont use the table name in any of the field names.

It's something on these lines,

 public function rawAddPrefix($query) {
   $query = str_replace(PHP_EOL, '', $query);
    $query = preg_replace('/\s+/', ' ', $query);
    preg_match_all("/(FROM|INTO|UPDATE|JOIN|DROP TABLE|TRUNCATE TABLE|CREATE TABLE|LOCK TABLE|FLASHBACK TABLE|ALTER TABLE|ANALYZE TABLE|DESCRIBE|EXPLAIN) [\\'\\´\\`]?(?!SELECT|DELETE|INSERT|REPLACE|UPDATE)([a-zA-Z0-9_-]+)[\\'\\´\\`]?/i", $query, $matches);
    $matches_unique = array_unique($matches[2]);

    foreach ($matches_unique as $table) {
        $query = str_replace($table, self::$prefix . $table, $query);
    }
    return $query;

}
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

1 participant