@@ -182,6 +182,20 @@ class Medoo
182182 */
183183 public $ errorInfo = null ;
184184
185+ /**
186+ * The keyword to connect the table alias.
187+ *
188+ * @var string
189+ */
190+ protected $ tableAliasConnector = ' AS ' ;
191+
192+ /**
193+ * The quote pattern string.
194+ *
195+ * @var string
196+ */
197+ protected $ quotePattern = '"$1" ' ;
198+
185199 /**
186200 * Regular expression pattern for valid table names.
187201 *
@@ -254,11 +268,7 @@ public function __construct(array $options)
254268 }
255269 }
256270
257- $ this ->type = strtolower ($ options ['type ' ]);
258-
259- if ($ this ->type === 'mariadb ' ) {
260- $ this ->type = 'mysql ' ;
261- }
271+ $ this ->setupType ($ options ['type ' ]);
262272
263273 if (isset ($ options ['logging ' ]) && is_bool ($ options ['logging ' ])) {
264274 $ this ->logging = $ options ['logging ' ];
@@ -506,6 +516,30 @@ public function __construct(array $options)
506516 }
507517 }
508518
519+ /**
520+ * Setup the database type.
521+ *
522+ * @return void
523+ */
524+ public function setupType (string $ type )
525+ {
526+ $ databaseType = strtolower ($ type );
527+
528+ if ($ databaseType === 'mariadb ' ) {
529+ $ databaseType = 'mysql ' ;
530+ }
531+
532+ if ($ databaseType === 'oracle ' ) {
533+ $ this ->tableAliasConnector = ' ' ;
534+ } elseif ($ databaseType === 'mysql ' ) {
535+ $ this ->quotePattern = '`$1` ' ;
536+ } elseif ($ databaseType === 'mssql ' ) {
537+ $ this ->quotePattern = '[$1] ' ;
538+ }
539+
540+ $ this ->type = $ databaseType ;
541+ }
542+
509543 /**
510544 * Generate a new map key for the placeholder.
511545 *
@@ -618,14 +652,9 @@ public function exec(string $statement, array $map = [], ?callable $callback = n
618652 */
619653 protected function generate (string $ statement , array $ map ): string
620654 {
621- $ identifier = [
622- 'mysql ' => '`$1` ' ,
623- 'mssql ' => '[$1] '
624- ];
625-
626655 $ statement = preg_replace (
627- '/(?! \'[^\s]+\s?)"([\p{L}_][\p{L}\p{N}@$#\-_]* )"(?!\s?[^\s]+ \')/u ' ,
628- $ identifier [ $ this ->type ] ?? ' "$1" ' ,
656+ '/(?! \'[^\s]+\s?)"( ' . $ this :: COLUMN_PATTERN . ' )"(?!\s?[^\s]+ \')/u ' ,
657+ $ this ->quotePattern ,
629658 $ statement
630659 );
631660
@@ -1214,7 +1243,7 @@ protected function selectContext(
12141243 if (isset ($ tableMatch ['table ' ], $ tableMatch ['alias ' ])) {
12151244 $ table = $ this ->tableQuote ($ tableMatch ['table ' ]);
12161245 $ tableAlias = $ this ->tableQuote ($ tableMatch ['alias ' ]);
1217- $ tableQuery = "{$ table } AS {$ tableAlias }" ;
1246+ $ tableQuery = "{$ table }{ $ this -> tableAliasConnector } {$ tableAlias }" ;
12181247 } else {
12191248 $ table = $ this ->tableQuote ($ table );
12201249 $ tableQuery = $ table ;
@@ -1352,7 +1381,7 @@ protected function buildJoin(string $table, array $join, array &$map): string
13521381 $ tableName = $ this ->tableQuote ($ match ['table ' ]);
13531382
13541383 if (isset ($ match ['alias ' ])) {
1355- $ tableName .= ' AS ' . $ this ->tableQuote ($ match ['alias ' ]);
1384+ $ tableName .= $ this -> tableAliasConnector . $ this ->tableQuote ($ match ['alias ' ]);
13561385 }
13571386
13581387 $ tableJoin [] = $ type [$ match ['join ' ]] . " JOIN {$ tableName } {$ relation }" ;
0 commit comments