|
5 | 5 | interface |
6 | 6 |
|
7 | 7 | uses |
8 | | - Classes, SysUtils, Types, dbstructures; |
| 8 | + Classes, SysUtils, Types, dbstructures, StrUtils; |
9 | 9 |
|
10 | 10 |
|
11 | 11 | const |
@@ -319,6 +319,13 @@ TMySQLLib = class(TDbLib) |
319 | 319 | constructor Create(UsedDllFile, HintDefaultDll: String); override; |
320 | 320 | function IsLibMariadb: Boolean; |
321 | 321 | end; |
| 322 | + |
| 323 | + TMySqlProvider = class(TSqlProvider) |
| 324 | + public |
| 325 | + function GetSql(AId: TQueryId): string; override; |
| 326 | + end; |
| 327 | + |
| 328 | + |
322 | 329 | var |
323 | 330 | MySQLKeywords: TStringList; |
324 | 331 | MySQLErrorCodes: TStringList; |
@@ -3221,6 +3228,110 @@ procedure TMySQLLib.AssignProcedures; |
3221 | 3228 | end; |
3222 | 3229 |
|
3223 | 3230 |
|
| 3231 | +{ TMySqlProvider } |
| 3232 | + |
| 3233 | +function TMySqlProvider.GetSql(AId: TQueryId): string; |
| 3234 | +begin |
| 3235 | + case AId of |
| 3236 | + qDatabaseDrop: Result := 'DROP DATABASE %s'; |
| 3237 | + qEmptyTable: Result := 'TRUNCATE '; |
| 3238 | + qRenameTable: Result := 'RENAME TABLE %s TO %s'; |
| 3239 | + qRenameView: Result := 'RENAME TABLE %s TO %s'; |
| 3240 | + qCurrentUserHost: Result := 'SELECT CURRENT_USER()'; |
| 3241 | + qLikeCompare: Result := '%s LIKE %s'; |
| 3242 | + qAddColumn: Result := 'ADD COLUMN %s'; |
| 3243 | + qChangeColumn: Result := 'CHANGE COLUMN %s %s'; |
| 3244 | + qGlobalStatus: Result := IfThen( |
| 3245 | + FNetType = ntMySQL_ProxySQLAdmin, |
| 3246 | + 'SELECT * FROM stats_mysql_global', |
| 3247 | + 'SHOW /*!50002 GLOBAL */ STATUS' |
| 3248 | + ); |
| 3249 | + qCommandsCounters: Result := IfThen( |
| 3250 | + FNetType = ntMySQL_ProxySQLAdmin, |
| 3251 | + 'SELECT * FROM stats_mysql_commands_counters', |
| 3252 | + 'SHOW /*!50002 GLOBAL */ STATUS LIKE ''Com\_%''' |
| 3253 | + ); |
| 3254 | + qSessionVariables: Result := 'SHOW VARIABLES'; |
| 3255 | + qGlobalVariables: Result := 'SHOW GLOBAL VARIABLES'; |
| 3256 | + qISSchemaCol: Result := '%s_SCHEMA'; |
| 3257 | + qUSEQuery: Result := 'USE %s'; |
| 3258 | + qKillQuery: Result := IfThen( |
| 3259 | + FNetType = ntMySQL_RDS, |
| 3260 | + 'CALL mysql.rds_kill_query(%d)', |
| 3261 | + IfThen( |
| 3262 | + FServerVersion >= 50000, |
| 3263 | + 'KILL QUERY %d', |
| 3264 | + 'KILL %d' |
| 3265 | + ) |
| 3266 | + ); |
| 3267 | + qKillProcess: Result := IfThen( |
| 3268 | + FNetType = ntMySQL_RDS, |
| 3269 | + 'CALL mysql.rds_kill(%d)', |
| 3270 | + 'KILL %d' |
| 3271 | + ); |
| 3272 | + qFuncLength: Result := 'LENGTH'; |
| 3273 | + qFuncCeil: Result := 'CEIL'; |
| 3274 | + qFuncLeft: Result := IfThen( |
| 3275 | + FNetType = ntMySQL_ProxySQLAdmin, |
| 3276 | + 'SUBSTR(%s, 1, %d)', |
| 3277 | + 'LEFT(%s, %d)' |
| 3278 | + ); |
| 3279 | + qFuncNow: Result := IfThen( |
| 3280 | + FNetType = ntMySQL_ProxySQLAdmin, |
| 3281 | + 'CURRENT_TIMESTAMP', |
| 3282 | + 'NOW()' |
| 3283 | + ); |
| 3284 | + qFuncLastAutoIncNumber: Result := 'LAST_INSERT_ID()'; |
| 3285 | + qLockedTables: Result := IfThen( |
| 3286 | + (FNetType <> ntMySQL_ProxySQLAdmin) and (FServerVersion >= 50124), |
| 3287 | + 'SHOW OPEN TABLES FROM %s WHERE in_use!=0', |
| 3288 | + '' |
| 3289 | + ); |
| 3290 | + qDisableForeignKeyChecks: Result := IfThen( |
| 3291 | + FServerVersion >= 40014, |
| 3292 | + 'SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0', |
| 3293 | + '' |
| 3294 | + ); |
| 3295 | + qEnableForeignKeyChecks: Result := IfThen( |
| 3296 | + FServerVersion >= 40014, |
| 3297 | + 'SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1)', |
| 3298 | + '' |
| 3299 | + ); |
| 3300 | + qForeignKeyDrop: Result := 'DROP FOREIGN KEY %s'; |
| 3301 | + qGetTableColumns: Result := ''; |
| 3302 | + qGetCollations: Result := IfThen( |
| 3303 | + FServerVersion >= 40100, |
| 3304 | + 'SHOW COLLATION', |
| 3305 | + '' |
| 3306 | + ); |
| 3307 | + // Issue #1917: MariaDB 10.10.1+ versions have additional collations in IS.COLLATION_CHARACTER_SET_APPLICABILITY |
| 3308 | + qGetCollationsExtended: Result := IfThen( |
| 3309 | + FServerVersion >= 101001, |
| 3310 | + 'SELECT'+ |
| 3311 | + ' FULL_COLLATION_NAME AS `Collation`'+ |
| 3312 | + ', CHARACTER_SET_NAME AS `Charset`'+ |
| 3313 | + ', ID AS `Id`'+ |
| 3314 | + ', IS_DEFAULT AS `Default`'+ |
| 3315 | + ', 0 AS `Sortlen`'+ |
| 3316 | + ' FROM information_schema.COLLATION_CHARACTER_SET_APPLICABILITY'+ |
| 3317 | + ' ORDER BY `Collation`', |
| 3318 | + '' |
| 3319 | + ); |
| 3320 | + qGetCharsets: Result := IfThen( |
| 3321 | + FServerVersion >= 40100, |
| 3322 | + 'SHOW CHARSET', |
| 3323 | + '' |
| 3324 | + ); |
| 3325 | + qGetRowCountApprox: Result := IfThen( |
| 3326 | + FNetType <> ntMySQL_ProxySQLAdmin, |
| 3327 | + 'SHOW TABLE STATUS LIKE :EscapedName', |
| 3328 | + '' |
| 3329 | + ); |
| 3330 | + else Result := inherited; |
| 3331 | + end; |
| 3332 | +end; |
| 3333 | + |
| 3334 | + |
3224 | 3335 | initialization |
3225 | 3336 |
|
3226 | 3337 | // Keywords copied from SynHighligherSQL |
|
0 commit comments