[GB.DB.MYSQL]

* NEW: Added the function PrimaryKey to _Index class.
* BUG: Rename in _Field class works correctly now.
* NEW: Added property Query to _MySQL class.
* OPT: Optimized procedure RunQuery in modMain.
* OPT: Optimized Modify procedure in _Table class.
* NEW: Added function Definition to _Routine class.
* OPT: Optimized Tables procedure in _Database class.
* NEW: Added Triggers procedure to  _Database class.
* NEW: Added Views procedure to  _Database class.

git-svn-id: svn://localhost/gambas/trunk@1538 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
David Villalobos Cambronero 2008-09-04 20:04:15 +00:00
parent 44e0814952
commit 031802f2f2
8 changed files with 63 additions and 6 deletions

View file

@ -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]

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
End
Private Function Query_Read() As String
Return modMain.$Query
End

View file

@ -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

View file

@ -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

View file

@ -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