[GB.DB.MYSQL]

* NEW: Deleted some unneeded lines.
* NEW: Added Info() function to _DataBase, _Table, _View, _Field
  that retrieves the symbol's information.
* NEW: Added Insert() function to _Table, it acts as a normal INSERT INTO.
* NEW: Optimizations in some functions and procedures.
* NEW: Added CBool function, to convert Gambas Bolean types to MySQL types.

git-svn-id: svn://localhost/gambas/trunk@1372 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
David Villalobos Cambronero 2008-05-12 19:01:13 +00:00
parent 0e60b5f87f
commit 9e6fc1ba7b
10 changed files with 142 additions and 50 deletions

View file

@ -22,7 +22,7 @@ m
Modify
m
(DataBase)s[(CharSet)s(Collation)s]
(DataBase)s[(Charset)s(Collation)s]
Delete
m
@ -30,7 +30,7 @@ m
Add
m
(DataBase)s[(CharSet)s(Collation)s]
(DataBase)s[(Charset)s(Collation)s]
Dump
m
@ -129,103 +129,103 @@ LONGBLOB
Bit
m
s
[(Lenght)i]
[(Length)i]
SignedFloat
m
s
(Lenght)i[(Decimals)i]
(Length)i[(Decimals)i]
UnsignedFloat
m
s
(Lenght)i[(Decimals)i]
(Length)i[(Decimals)i]
SignedDouble
m
s
(Lenght)i[(Decimals)i]
(Length)i[(Decimals)i]
UnsignedDouble
m
s
(Lenght)i[(Decimals)i]
(Length)i[(Decimals)i]
SignedDoublePrecision
m
s
(Lenght)i[(Decimals)i]
(Length)i[(Decimals)i]
UnsignedDoublePrecision
m
s
(Lenght)i[(Decimals)i]
(Length)i[(Decimals)i]
SignedReal
m
s
(Lenght)i[(Decimals)i]
(Length)i[(Decimals)i]
UnsignedReal
m
s
(Lenght)i[(Decimals)i]
(Length)i[(Decimals)i]
SignedDecimal
m
s
(Lenght)i[(Decimals)i]
(Length)i[(Decimals)i]
UnsignedDecimal
m
s
(Lenght)i[(Decimals)i]
(Length)i[(Decimals)i]
SignedDec
m
s
(Lenght)i[(Decimals)i]
(Length)i[(Decimals)i]
UnsignedDec
m
s
(Lenght)i[(Decimals)i]
(Length)i[(Decimals)i]
Year
m
s
[(Lenght)i]
[(Length)i]
Char
m
s
[(Lenght)i(CharSet)s(Collation)s]
[(Length)i(Charset)s(Collation)s]
VarChar
m
s
(Lenght)i[(CharSet)s(Collation)s]
(Length)i[(Charset)s(Collation)s]
Binary
m
s
(Lenght)i
(Length)i
VarBinary
m
s
(Lenght)i
(Length)i
TinyText
m
s
[(Lenght)i(CharSet)s(Collation)s]
[(Length)i(Charset)s(Collation)s]
Blob
m
s
[(Lenght)i]
[(Length)i]
Text
m
s
[(Lenght)i(CharSet)s(Collation)s]
[(Length)i(Charset)s(Collation)s]
MediumText
m
s
[(CharSet)s(Collation)s]
[(Charset)s(Collation)s]
LongText
m
s
[(CharSet)s(Collation)s]
[(Charset)s(Collation)s]
Enum
m
s
(Values)String[];[(CharSet)s(Collation)s]
(Values)String[];[(Charset)s(Collation)s]
Set
m
s
(Values)String[];[(CharSet)s(Collation)s]
(Values)String[];[(Charset)s(Collation)s]
#_Field
CA
@ -263,7 +263,7 @@ Engine
p
s
CharSet
Charset
p
s
@ -295,6 +295,10 @@ View
r
_View
User
r
_User
Confirm
p
b
@ -309,7 +313,7 @@ m
Add
m
(Table)s[(Engine)s(CharSet)s]
(Table)s[(Engine)s(Charset)s]
Delete
m
@ -318,6 +322,21 @@ LoadData
m
(Table)s(File)s
#_User
CA
Delete
m
(User)s(Host)s[(IfExists)b]
Add
m
(User)s(Password)s(Host)s
Grant
m
(Privileges)String[];(User)s(Password)s(Host)s(DataBase)s
#_View
CA

View file

@ -10,30 +10,18 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: modMain.module:33
#: modMain.module:41
msgid "Do you really want to execute the following statement?"
msgstr "¿Realmente desea ejecutar la siguiente sentencia?"
#: modMain.module:33
#: modMain.module:41
msgid "&Yes"
msgstr "&Sí"
#: modMain.module:33
#: modMain.module:41
msgid "&No"
msgstr "&No"
#: _MySQL.class:28
msgid "Not a MySQL connection."
msgstr "No es una conexión MySQL."
#: _MySQL.class:67
msgid "Character Set not valid."
msgstr "Character Set no válido."
#: _MySQL.class:93
msgid "Collation not valid."
msgstr "Callation no válida."
#: .project:1
msgid "mysql"
msgstr "mysql"
@ -42,6 +30,14 @@ msgstr "mysql"
msgid "Creates MySQL statements and executes them."
msgstr "Crea sentencias MySQL y las ejecuta."
#: _Table.class:9
msgid "Action no allowed."
msgstr "Acción no permitida."
#~ msgid "Not a MySQL connection."
#~ msgstr "No es una conexión MySQL."
#~ msgid "Character Set not valid."
#~ msgstr "Character Set no válido."
#~ msgid "Collation not valid."
#~ msgstr "Callation no válida."
#~ msgid "Action no allowed."
#~ msgstr "Acción no permitida."

View file

@ -6,4 +6,5 @@ _Field
_Index
_MySQL
_Table
_User
_View

View file

@ -43,7 +43,6 @@ Public Procedure Dump(Optional File As String)
sTmp = "mysqldump -u " & modMain.$Connection.User & " -h " & modMain.$Connection.Host
If modMain.$Connection.Port Then sTmp &= " -P " & modMain.$Connection.Port
sTmp &= " --password='" & modMain.$Connection.Password & "' -B " & modMain.$Connection.Name
'If Tables Then sTmp &= " " & modMain.ArrayToString(Tables, True)
If File Then
sTmp &= " > " & File
Else
@ -52,3 +51,10 @@ Public Procedure Dump(Optional File As String)
Shell sTmp For Read
End
Public Function Info(DataBase As String) As String
modMain.$hResult = modMain.$Connection.Exec("SHOW CREATE DATABASE " & DB.Quote(DataBase))
Return modMain.$hResult["Create Database"]
End

View file

@ -48,3 +48,18 @@ Public Procedure ForeignKey(Field As String, RefTable As String, RefField As Str
modMain.$ForeignKey.Add($sTmp)
End
Public Function Info(Table As String, Field As String) As String
Dim sDefinition As String
modMain.$hResult = modMain.$Connection.Exec("SHOW COLUMNS FROM " & Table & " LIKE '" & Field & "'")
sDefinition &= "Field: " & modMain.$hResult!Field & GB.NewLine
sDefinition &= "Type: " & modMain.$hResult!Type & GB.NewLine
sDefinition &= "Null: " & modMain.$hResult!Null & GB.NewLine
sDefinition &= "Key: " & modMain.$hResult!Key & GB.NewLine
sDefinition &= "Default: " & modMain.$hResult!Default & GB.NewLine
sDefinition &= "Extra: " & modMain.$hResult!Extra
Return sDefinition
End

View file

@ -152,3 +152,16 @@ Private Function User_Read() As _User
Return $User
End
Public Function CBool(Value As Variant) As Integer
Select (Value)
Case -1, "T"
Return 1
Case 0
Return 0
Default
Error.Raise("Invalid value")
End Select
End

View file

@ -51,3 +51,38 @@ Public Procedure LoadData(Table As String, File As String)
modMain.RunQuery(modMain.$Query)
End
Public Function Info(Table As String) As String
modMain.$hResult = modMain.$Connection.Exec("SHOW CREATE TABLE " & DB.Quote(Table))
Return modMain.$hResult["Create Table"]
End
Public Procedure Insert(Table As String, Fields As String[], Values As String[])
Dim iCounter As Integer
modMain.$Query = "INSERT INTO " & DB.Quote(Table)
If Upper(Fields[0]) = "ALL" Then
modMain.$Query &= " VALUES ("
Else
modMain.$Query &= " (" & modMain.ArrayToString(Fields, False) & ") 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

View file

@ -27,7 +27,7 @@ Public Procedure Grant(Privileges As String[], User As String, Password As Strin
Dim iCounter As Integer
If Privileges[0] = "All" Or Privileges[0] = "all" Or Privileges[0] = "ALL" Then
If Upper(Privileges[0]) = "ALL" Then
modMain.$Query = "GRANT ALL PRIVILEGES"
Else
modMain.$Query = "GRANT "

View file

@ -27,3 +27,10 @@ Public Procedure Delete(Views As String[], IfExists As Boolean)
modMain.RunQuery(modMain.$Query)
End
Public Function Info(View As String) As String
modMain.$hResult = modMain.$Connection.Exec("SHOW CREATE VIEW " & DB.Quote(View))
Return modMain.$hResult["Create View"]
End

View file

@ -9,6 +9,7 @@ Public $PrimaryKey As String
Public $Connection As New Connection
Public $Confirm As Boolean = False
Public $Process As Process
Public $hResult As Result
Public Sub SetConnection(hCon As Connection)
@ -17,7 +18,6 @@ Public Sub SetConnection(hCon As Connection)
End
Public Function ArrayToString(Array As String[], Quote As Boolean) As String
Dim iCounter As Integer