diff --git a/gb.db.mysql/src/gb.db.mysql/.info b/gb.db.mysql/src/gb.db.mysql/.info index 513c8a985..bed13e73a 100644 --- a/gb.db.mysql/src/gb.db.mysql/.info +++ b/gb.db.mysql/src/gb.db.mysql/.info @@ -371,6 +371,10 @@ Quote m s (Value)v +Use +m + +(Database)s #_Routines CA @@ -502,3 +506,7 @@ Info m s (View)s[(Database)s] +Definition +m +s +(View)s[(Database)s] diff --git a/gb.db.mysql/src/gb.db.mysql/_DataBase.class b/gb.db.mysql/src/gb.db.mysql/_DataBase.class index a71ccdf0c..c6d3881c9 100644 --- a/gb.db.mysql/src/gb.db.mysql/_DataBase.class +++ b/gb.db.mysql/src/gb.db.mysql/_DataBase.class @@ -79,14 +79,40 @@ Public Function Tables(Optional Database As String) As String[] Dim asTables As New String[] If Not Database Then Database = modMain.$Connection.Name - modMain.$hResult = modMain.$Connection.Exec("SHOW TABLES FROM `" & Database & "`") + modMain.$hResult = modMain.$Connection.Exec("SELECT `TABLE_NAME` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = '" & Database & "' AND TABLE_TYPE = 'BASE TABLE'") For Each modMain.$hResult - asTables.Add(modMain.$hResult["Tables_in_" & Database]) + asTables.Add(modMain.$hResult!TABLE_NAME) Next Return asTables End +Public Function Views(Optional Database As String) As String[] + + Dim asViews As New String[] + + If Not Database Then Database = modMain.$Connection.Name + modMain.$hResult = modMain.$Connection.Exec("SELECT `TABLE_NAME` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = '" & Database & "' AND TABLE_TYPE = 'VIEW'") + For Each modMain.$hResult + asViews.Add(modMain.$hResult!TABLE_NAME) + Next + Return asViews + +End + +Public Function Triggers(Optional Database As String) As String[] + + Dim asTriggers As New String[] + + If Not Database Then Database = modMain.$Connection.Name + modMain.$hResult = modMain.$Connection.Exec("SELECT `TRIGGER_NAME` FROM `information_schema`.`TRIGGERS` WHERE `TRIGGER_SCHEMA` = '" & Database & "'") + For Each modMain.$hResult + asTriggers.Add(modMain.$hResult!TRIGGER_NAME) + Next + Return asTriggers + +End + Public Function Charset(Optional Database As String) As String If Not Database Then Database = modMain.$Connection.Name diff --git a/gb.db.mysql/src/gb.db.mysql/_Field.class b/gb.db.mysql/src/gb.db.mysql/_Field.class index ae541a210..3f9418ff5 100644 --- a/gb.db.mysql/src/gb.db.mysql/_Field.class +++ b/gb.db.mysql/src/gb.db.mysql/_Field.class @@ -82,6 +82,6 @@ End Public Procedure Rename(Table As String, Field As String, NewField As String, Optional Database As String) If Not Database Then Database = modMain.$Connection.Name - modMain.$Connection.Exec("ALTER TABLE `" & Database & "`.`" & Table & "` CHANGE COLUMN `" & Field & "` `" & NewField & "` " & Definition(Database, Table, Field)) + modMain.$Connection.Exec("ALTER TABLE `" & Database & "`.`" & Table & "` CHANGE COLUMN `" & Field & "` `" & NewField & "` " & Definition(Table, Field, Database)) End diff --git a/gb.db.mysql/src/gb.db.mysql/_Index.class b/gb.db.mysql/src/gb.db.mysql/_Index.class index fe910bf59..e641dc921 100644 --- a/gb.db.mysql/src/gb.db.mysql/_Index.class +++ b/gb.db.mysql/src/gb.db.mysql/_Index.class @@ -20,3 +20,11 @@ Public Procedure Delete(Table As String, Index As String, Optional Database As S modMain.RunQuery("DROP INDEX `" & Index & "` ON `" & Database & "`.`" & Table & "`") End + +Public Procedure PrimaryKey(Table As String, Columns As String[], Optional Database As String) + + If Not Database Then Database = modMain.$Connection.Name + Try modMain.RunQuery("ALTER TABLE `" & Database & "`.`" & Table & "` DROP PRIMARY KEY") + modMain.RunQuery("ALTER TABLE `" & Database & "`.`" & Table & "` ADD PRIMARY KEY (" & modMain.ArrayToString(Columns, True) & ")") + +End diff --git a/gb.db.mysql/src/gb.db.mysql/_MySQL.class b/gb.db.mysql/src/gb.db.mysql/_MySQL.class index 154878cdc..3ff959463 100644 --- a/gb.db.mysql/src/gb.db.mysql/_MySQL.class +++ b/gb.db.mysql/src/gb.db.mysql/_MySQL.class @@ -39,6 +39,7 @@ Property Read Engines As String[] Property Read Charsets As String[] Property Read Databases As String[] Property Read Users As String[] +Property Read Query As String Private Function Engine_Read() As String @@ -240,4 +241,10 @@ Public Procedure Use(Database As String) modMain.$Connection.Exec("USE " & Database) modMain.$Connection.Name = Database -End \ No newline at end of file +End + +Private Function Query_Read() As String + + Return modMain.$Query + +End diff --git a/gb.db.mysql/src/gb.db.mysql/_Routines.class b/gb.db.mysql/src/gb.db.mysql/_Routines.class index 943ac7669..34dbc6183 100644 --- a/gb.db.mysql/src/gb.db.mysql/_Routines.class +++ b/gb.db.mysql/src/gb.db.mysql/_Routines.class @@ -55,3 +55,10 @@ Public Function Info(Routine As String, Optional Database As String) As String End Select End + +Public Function Definition(Routine As String, Optional Database As String) As String + + If Not Database Then Database = modMain.$Connection.Name + Return modMain.$Connection.Exec("SELECT `body` FROM `mysql`.`proc` WHERE `db` = '" & Database & "' AND `name` = '" & Routine & "'")["body"].Data + +End diff --git a/gb.db.mysql/src/gb.db.mysql/_Table.class b/gb.db.mysql/src/gb.db.mysql/_Table.class index 8b3bc5bf8..e31aa61fc 100644 --- a/gb.db.mysql/src/gb.db.mysql/_Table.class +++ b/gb.db.mysql/src/gb.db.mysql/_Table.class @@ -10,7 +10,7 @@ Public Procedure Modify(Table As String, Action As String, Optional Symbol As St Select (Action) Case "DROP" modMain.$Query &= Action & " COLUMN `" & Symbol & "`" - Case "ADD", "MODIFY", "CHANGE" + Case "ADD", "MODIFY", "CHANGE", "ALTER" modMain.$Query &= Action & " COLUMN `" & Symbol & "` " & Definition Case "CHARACTER SET" modMain.$Query &= "CONVERT TO CHARACTER SET " & Definition diff --git a/gb.db.mysql/src/gb.db.mysql/modMain.module b/gb.db.mysql/src/gb.db.mysql/modMain.module index 942335065..86f3c2a7a 100644 --- a/gb.db.mysql/src/gb.db.mysql/modMain.module +++ b/gb.db.mysql/src/gb.db.mysql/modMain.module @@ -35,9 +35,10 @@ End Public Procedure RunQuery(Query As String) + modMain.$Query = Query $Connection.Exec(Query) Catch - Error.Raise(Error.Text) + Error.Raise("MySQL: " & Error.Text) End