[GB.DB.MYSQL]
* BUG: Class _Trigger works correctly now. git-svn-id: svn://localhost/gambas/trunk@1502 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
576034a621
commit
74cf500e2b
3 changed files with 151 additions and 139 deletions
|
@ -22,11 +22,19 @@ m
|
|||
Modify
|
||||
m
|
||||
|
||||
(DataBase)s[(Charset)s(Collation)s]
|
||||
[(DataBase)s(Charset)s(Collation)s]
|
||||
Charset
|
||||
m
|
||||
s
|
||||
[(DataBase)s]
|
||||
Collation
|
||||
m
|
||||
s
|
||||
[(DataBase)s]
|
||||
Delete
|
||||
m
|
||||
|
||||
(DataBase)s(IfExists)b
|
||||
[(DataBase)s(IfExists)b]
|
||||
Add
|
||||
m
|
||||
|
||||
|
@ -34,11 +42,15 @@ m
|
|||
Dump
|
||||
m
|
||||
|
||||
[(File)s]
|
||||
[(DataBase)s(Tables)String[];(File)s(Options)String[];(Replace)b]
|
||||
Tables
|
||||
m
|
||||
String[]
|
||||
[(DataBase)s]
|
||||
Info
|
||||
m
|
||||
s
|
||||
(DataBase)s
|
||||
[(DataBase)s]
|
||||
#_DataTypes
|
||||
|
||||
CA
|
||||
|
@ -256,18 +268,26 @@ m
|
|||
Info
|
||||
m
|
||||
s
|
||||
(Table)s(Field)s
|
||||
(Table)s(Field)s[(Database)s]
|
||||
Definition
|
||||
m
|
||||
s
|
||||
(Table)s(Field)s[(Database)s]
|
||||
Rename
|
||||
m
|
||||
|
||||
(Table)s(Field)s(NewField)s[(Database)s]
|
||||
#_Index
|
||||
|
||||
CA
|
||||
Add
|
||||
m
|
||||
|
||||
(Index)s(Columns)String[];[(Table)s]
|
||||
(Index)s(Columns)String[];[(Table)s(Database)s]
|
||||
Delete
|
||||
m
|
||||
|
||||
(Table)s(Index)s
|
||||
(Table)s(Index)s[(Database)s]
|
||||
#_MySQL
|
||||
|
||||
CA
|
||||
|
@ -311,10 +331,34 @@ User
|
|||
r
|
||||
_User
|
||||
|
||||
Trigger
|
||||
r
|
||||
_Trigger
|
||||
|
||||
Routines
|
||||
r
|
||||
_Routines
|
||||
|
||||
Collations
|
||||
r
|
||||
String[]
|
||||
|
||||
Engines
|
||||
r
|
||||
String[]
|
||||
|
||||
Charsets
|
||||
r
|
||||
String[]
|
||||
|
||||
Databases
|
||||
r
|
||||
String[]
|
||||
|
||||
Users
|
||||
r
|
||||
String[]
|
||||
|
||||
CBool
|
||||
m
|
||||
i
|
||||
|
@ -333,15 +377,15 @@ CA
|
|||
Add
|
||||
m
|
||||
|
||||
(Routine)s(Type)i(Statement)s[(Parameters)String[];(Return)s]
|
||||
(Routine)s(Statement)s[(Parameters)String[];(Returns)s(Database)s]
|
||||
Delete
|
||||
m
|
||||
|
||||
(Routine)s(Type)i(IfExists)b
|
||||
(Routine)s[(IfExists)b(Database)s]
|
||||
Info
|
||||
m
|
||||
s
|
||||
(Routine)s(Type)i
|
||||
(Routine)s[(Database)s]
|
||||
#_Table
|
||||
|
||||
CA
|
||||
|
@ -353,10 +397,18 @@ Add
|
|||
m
|
||||
|
||||
(Table)s[(Engine)s(Charset)s]
|
||||
Engine
|
||||
m
|
||||
s
|
||||
(Table)s[(Database)s]
|
||||
Charset
|
||||
m
|
||||
s
|
||||
(Table)s[(Database)s]
|
||||
Delete
|
||||
m
|
||||
|
||||
(Tables)String[];(IfExists)b
|
||||
(Tables)String[];[(IfExists)b]
|
||||
LoadData
|
||||
m
|
||||
|
||||
|
@ -369,10 +421,73 @@ Insert
|
|||
m
|
||||
|
||||
(Table)s(Fields)String[];(Values)String[];
|
||||
Fields
|
||||
m
|
||||
String[]
|
||||
(Table)s[(Database)s]
|
||||
Rename
|
||||
m
|
||||
|
||||
(Table)s(NewTable)s
|
||||
Collation
|
||||
m
|
||||
s
|
||||
(Table)s[(Database)s]
|
||||
Truncate
|
||||
m
|
||||
|
||||
(Table)s[(Database)s]
|
||||
#_Trigger
|
||||
|
||||
CA
|
||||
Modify
|
||||
m
|
||||
|
||||
(Table)s(Action)s[(Symbol)s(Definition)s]
|
||||
Add
|
||||
m
|
||||
|
||||
(Table)s[(Engine)s(Charset)s]
|
||||
Engine
|
||||
m
|
||||
s
|
||||
(Table)s[(Database)s]
|
||||
Charset
|
||||
m
|
||||
s
|
||||
(Table)s[(Database)s]
|
||||
Delete
|
||||
m
|
||||
|
||||
(Tables)String[];[(IfExists)b]
|
||||
LoadData
|
||||
m
|
||||
|
||||
(Table)s(File)s
|
||||
Info
|
||||
m
|
||||
s
|
||||
(Table)s
|
||||
Insert
|
||||
m
|
||||
|
||||
(Table)s(Fields)String[];(Values)String[];
|
||||
Fields
|
||||
m
|
||||
String[]
|
||||
(Table)s[(Database)s]
|
||||
Rename
|
||||
m
|
||||
|
||||
(Table)s(NewTable)s
|
||||
Collation
|
||||
m
|
||||
s
|
||||
(Table)s[(Database)s]
|
||||
Truncate
|
||||
m
|
||||
|
||||
(Table)s[(Database)s]
|
||||
#_User
|
||||
|
||||
CA
|
||||
|
@ -387,7 +502,7 @@ m
|
|||
Grant
|
||||
m
|
||||
|
||||
(Privileges)String[];(User)s(Password)s(Host)s(DataBase)s
|
||||
(Privileges)String[];(User)s(Password)s(Host)s[(DataBase)s]
|
||||
Info
|
||||
m
|
||||
s
|
||||
|
@ -395,7 +510,7 @@ s
|
|||
Revoke
|
||||
m
|
||||
|
||||
(Privileges)String[];(User)s(Host)s(DataBase)s
|
||||
(Privileges)String[];(User)s(Host)s[(DataBase)s]
|
||||
Rename
|
||||
m
|
||||
|
||||
|
@ -418,8 +533,8 @@ m
|
|||
Delete
|
||||
m
|
||||
|
||||
(Views)String[];(IfExists)b
|
||||
(Views)String[];[(IfExists)b]
|
||||
Info
|
||||
m
|
||||
s
|
||||
(View)s
|
||||
(View)s[(Database)s]
|
||||
|
|
|
@ -7,5 +7,6 @@ _Index
|
|||
_MySQL
|
||||
_Routines
|
||||
_Table
|
||||
_Trigger
|
||||
_User
|
||||
_View
|
||||
|
|
|
@ -3,142 +3,38 @@
|
|||
Export
|
||||
Create Static
|
||||
|
||||
Public Procedure Modify(Table As String, Action As String, Optional Symbol As String, Optional Definition As String)
|
||||
' Public Procedure Modify()
|
||||
'
|
||||
'
|
||||
'
|
||||
' End
|
||||
|
||||
Action = Upper(Action)
|
||||
modMain.$Query = "ALTER TABLE `" & Table & "` "
|
||||
Select (Action)
|
||||
Case "DROP"
|
||||
modMain.$Query &= Action & " COLUMN `" & Symbol & "`"
|
||||
Case "ADD", "MODIFY", "CHANGE"
|
||||
modMain.$Query &= Action & " COLUMN `" & Symbol & "` " & Definition
|
||||
Case "CHARACTER SET"
|
||||
modMain.$Query &= "CONVERT TO CHARACTER SET " & Definition
|
||||
Case "ENGINE"
|
||||
modMain.$Query &= "ENGINE " & Definition
|
||||
Default
|
||||
Error.Raise("Invalid Action")
|
||||
End Select
|
||||
modMain.RunQuery(modMain.$Query)
|
||||
Public Procedure Add(Trigger As String, Table As String, {Time} As String, {Event} As String, Statement As String, Optional Database As String)
|
||||
|
||||
If Not Database Then Database = modMain.$Connection.Name
|
||||
modMain.RunQuery("CREATE TRIGGER `" & Trigger & "` " & {Time} & " " & {Event} & " ON `" & Database & "`.`" & Table & "` FOR EACH ROW " & Statement)
|
||||
|
||||
End
|
||||
|
||||
Public Procedure Add(Table As String, Optional Engine As String, Optional Charset As String)
|
||||
Public Procedure Delete(Trigger As String, IfExists As Boolean, Optional DataBase As String)
|
||||
|
||||
'Construc the table statement
|
||||
If Not Charset Then Charset = modMain.$Connection.MySQL.Charset
|
||||
If Not Engine Then Engine = modMain.$Connection.MySQL.Engine
|
||||
modMain.$Query = "CREATE TABLE `" & Table & "` ("
|
||||
modMain.$Query &= modMain.ArrayToString(modMain.$FieldDefinition, False)
|
||||
If modMain.$PrimaryKey Then modMain.$Query &= modMain.$PrimaryKey
|
||||
If modMain.$Index.Count Then modMain.$Query &= ", " & modMain.ArrayToString(modMain.$Index, False)
|
||||
If modMain.$ForeignKey.Count Then modMain.$Query &= ", " & modMain.ArrayToString(modMain.$ForeignKey, False)
|
||||
modMain.$Query &= ") ENGINE = " & Engine & " DEFAULT CHARSET = " & Charset
|
||||
|
||||
'Clears all the information from this table to be ready for the next one
|
||||
modMain.$FieldDefinition.Clear()
|
||||
modMain.$PrimaryKey = Null
|
||||
modMain.$ForeignKey.Clear()
|
||||
modMain.$Index.Clear()
|
||||
|
||||
'Runs the query
|
||||
modMain.RunQuery(modMain.$Query)
|
||||
|
||||
End
|
||||
|
||||
Public Procedure Delete(Tables As String[], Optional IfExists As Boolean)
|
||||
|
||||
If Not IfExists Then IfExists = False
|
||||
modMain.$Query = "DROP TABLE "
|
||||
If Not Database Then Database = modMain.$Connection.Name
|
||||
modMain.$Query = "DROP TRIGGER "
|
||||
If IfExists Then modMain.$Query &= "IF EXISTS "
|
||||
modMain.$Query &= modMain.ArrayToString(Tables, True)
|
||||
modMain.$Query &= "`" & DataBase & "`.`" & Trigger & "`"
|
||||
modMain.RunQuery(modMain.$Query)
|
||||
|
||||
End
|
||||
|
||||
Public Procedure LoadData(Table As String, File As String)
|
||||
|
||||
modMain.RunQuery("LOAD DATA LOCAL INFILE '" & File & "' INTO TABLE `" & Table & "`")
|
||||
|
||||
End
|
||||
|
||||
Public Function Info(Table As String) As String
|
||||
|
||||
Return modMain.$Connection.Exec("SHOW CREATE TABLE `" & Table & "`")!"Create Table"
|
||||
|
||||
End
|
||||
|
||||
Public Procedure Insert(Table As String, Fields As String[], Values As String[])
|
||||
|
||||
Dim iCounter As Integer
|
||||
|
||||
modMain.$Query = "INSERT INTO `" & Table & "`"
|
||||
If Upper(Fields[0]) = "ALL" Then
|
||||
modMain.$Query &= " VALUES ("
|
||||
Else
|
||||
modMain.$Query &= " (" & modMain.ArrayToString(Fields, True) & ") VALUES ("
|
||||
Endif
|
||||
'If the Value is string type, we need to use the Apostrophe caracter
|
||||
For iCounter = 0 To Values.Count - 1
|
||||
If (IsNumber(Val(Values[iCounter]))) Then
|
||||
modMain.$Query &= Values[iCounter] & ", "
|
||||
Else
|
||||
If Upper(Values[iCounter]) = "NULL" Or Upper(Values[iCounter]) = "TRUE" Or Upper(Values[iCounter]) = "FALSE" Then
|
||||
modMain.$Query &= Values[iCounter] & ", "
|
||||
Else
|
||||
modMain.$Query &= "'" & Values[iCounter] & "', "
|
||||
Endif
|
||||
Endif
|
||||
Next
|
||||
modMain.$Query = Mid(modMain.$Query, 1, Len(modMain.$Query) - 2) 'Strips the last two characters
|
||||
modMain.$Query &= ")"
|
||||
modMain.RunQuery(modMain.$Query)
|
||||
|
||||
End
|
||||
|
||||
Public Procedure Rename(Table As String, NewTable As String)
|
||||
|
||||
modMain.RunQuery("RENAME TABLE `" & Table & "` TO `" & NewTable & "`")
|
||||
|
||||
End
|
||||
|
||||
Public Function Fields(Table As String, Optional Database As String) As String[]
|
||||
|
||||
Dim asFields As New String[]
|
||||
Public Function Info(Trigger As String, Optional DataBase As String) As String
|
||||
|
||||
If Not Database Then Database = modMain.$Connection.Name
|
||||
modMain.$hResult = modMain.$Connection.Exec("SHOW COLUMNS FROM `" & Database & "`.`" & Table & "`")
|
||||
For Each modMain.$hResult
|
||||
asFields.Add(modMain.$hResult!Field)
|
||||
Next
|
||||
Return asFields
|
||||
Return modMain.$Connection.Exec("SELECT `ACTION_STATEMENT` FROM `information_schema`.`TRIGGERS` WHERE `TRIGGER_SCHEMA` = '" & Database & "' AND `TRIGGER_NAME` = '" & Trigger & "'")!ACTION_STATEMENT
|
||||
|
||||
End
|
||||
|
||||
Public Function Charset(Table As String, Optional DataBase As String) As String
|
||||
|
||||
If Not Database Then Database = modMain.$Connection.Name
|
||||
Return modMain.$Connection.Exec("SELECT `a`.`CHARACTER_SET_NAME` FROM `information_schema`.`COLLATIONS` `a`, `information_schema`.`TABLES` `b` WHERE `b`.`TABLE_SCHEMA` = '" & Database & "' AND `b`.`TABLE_NAME` = '" & Table & "' AND `a`.`COLLATION_NAME` = `b`.`TABLE_COLLATION`")!CHARACTER_SET_NAME
|
||||
|
||||
End
|
||||
|
||||
Public Function Collation(Table As String, Optional DataBase As String) As String
|
||||
|
||||
If Not Database Then Database = modMain.$Connection.Name
|
||||
Return modMain.$Connection.Exec("SELECT `TABLE_COLLATION` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = '" & Database & "' AND `TABLE_NAME` = '" & Table & "'")!TABLE_COLLATION
|
||||
|
||||
End
|
||||
|
||||
Public Function Engine(Table As String, Optional DataBase As String) As String
|
||||
|
||||
If Not Database Then Database = modMain.$Connection.Name
|
||||
Return modMain.$Connection.Exec("SELECT `ENGINE` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = '" & Database & "' AND `TABLE_NAME` = '" & Table & "'")!ENGINE
|
||||
|
||||
End
|
||||
|
||||
Public Procedure Truncate(Table As String, Optional Database As String)
|
||||
|
||||
If Not Database Then Database = modMain.$Connection.Name
|
||||
modMain.RunQuery("TRUNCATE TABLE `" & Database & "`.`" & Table & "`")
|
||||
|
||||
End
|
||||
' Public Procedure Rename(Table As String, NewTable As String)
|
||||
'
|
||||
'
|
||||
'
|
||||
' End
|
||||
|
|
Loading…
Reference in a new issue