From 009463c394c542ebec46bff13989e305ec8cf8a7 Mon Sep 17 00:00:00 2001 From: David Villalobos Cambronero Date: Wed, 24 Sep 2008 22:07:53 +0000 Subject: [PATCH] [GB.DB.MYSQL] * OPT: Store every query in a variable, so it can be retrived with _MySQL.Query. git-svn-id: svn://localhost/gambas/trunk@1594 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- gb.db.mysql/src/gb.db.mysql/.info | 4 ++++ gb.db.mysql/src/gb.db.mysql/.project | 1 + gb.db.mysql/src/gb.db.mysql/_DataBase.class | 21 ++++++++++++++------- gb.db.mysql/src/gb.db.mysql/_Field.class | 9 ++++++--- gb.db.mysql/src/gb.db.mysql/_MySQL.class | 21 ++++++++++++++------- gb.db.mysql/src/gb.db.mysql/_Routines.class | 9 ++++++--- gb.db.mysql/src/gb.db.mysql/_Table.class | 15 ++++++++++----- gb.db.mysql/src/gb.db.mysql/_Trigger.class | 3 ++- gb.db.mysql/src/gb.db.mysql/_User.class | 9 ++++++--- gb.db.mysql/src/gb.db.mysql/_View.class | 8 +++++--- 10 files changed, 68 insertions(+), 32 deletions(-) diff --git a/gb.db.mysql/src/gb.db.mysql/.info b/gb.db.mysql/src/gb.db.mysql/.info index b19ca7977..4392764d0 100644 --- a/gb.db.mysql/src/gb.db.mysql/.info +++ b/gb.db.mysql/src/gb.db.mysql/.info @@ -59,6 +59,10 @@ Triggers m String[] [(Database)s] +Routines +m +String[] +[(Database)s] #_DataTypes CA diff --git a/gb.db.mysql/src/gb.db.mysql/.project b/gb.db.mysql/src/gb.db.mysql/.project index f8b080612..c82622ae9 100644 --- a/gb.db.mysql/src/gb.db.mysql/.project +++ b/gb.db.mysql/src/gb.db.mysql/.project @@ -1,4 +1,5 @@ # Gambas Project File 3.0 +# Compiled with Gambas 2.99.0 (r1566) Title=mysql Startup=modMain Icon=logo.png diff --git a/gb.db.mysql/src/gb.db.mysql/_DataBase.class b/gb.db.mysql/src/gb.db.mysql/_DataBase.class index a87e875ae..acac9fcaf 100644 --- a/gb.db.mysql/src/gb.db.mysql/_DataBase.class +++ b/gb.db.mysql/src/gb.db.mysql/_DataBase.class @@ -70,7 +70,8 @@ End Public Function Info(Optional Database As String) As String If Not Database Then Database = modMain.$Connection.Name - Return modMain.$Connection.Exec("SHOW CREATE DATABASE `" & Database & "`")!"Create Database" + modMain.$Query = "SHOW CREATE DATABASE `" & Database & "`" + Return modMain.$Connection.Exec(modMain.$Query)!"Create Database" End @@ -79,7 +80,8 @@ 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("SELECT `TABLE_NAME` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = '" & Database & "' AND TABLE_TYPE = 'BASE TABLE'") + modMain.$Query = "SELECT `TABLE_NAME` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = '" & Database & "' AND TABLE_TYPE = 'BASE TABLE'" + modMain.$hResult = modMain.$Connection.Exec(modMain.$Query) For Each modMain.$hResult asTables.Add(modMain.$hResult!TABLE_NAME) Next @@ -92,7 +94,8 @@ 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'") + modMain.$Query = "SELECT `TABLE_NAME` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = '" & Database & "' AND TABLE_TYPE = 'VIEW'" + modMain.$hResult = modMain.$Connection.Exec(modMain.$Query) For Each modMain.$hResult asViews.Add(modMain.$hResult!TABLE_NAME) Next @@ -105,7 +108,8 @@ 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 & "'") + modMain.$Query = "SELECT `TRIGGER_NAME` FROM `information_schema`.`TRIGGERS` WHERE `TRIGGER_SCHEMA` = '" & Database & "'" + modMain.$hResult = modMain.$Connection.Exec(modMain.$Query) For Each modMain.$hResult asTriggers.Add(modMain.$hResult!TRIGGER_NAME) Next @@ -118,7 +122,8 @@ Public Function Routines(Optional Database As String) As String[] Dim asRoutines As New String[] If Not Database Then Database = modMain.$Connection.Name - modMain.$hResult = modMain.$Connection.Exec("SELECT `name` FROM `mysql`.`proc` WHERE `db` = '" & Database & "'") + modMain.$Query = "SELECT `name` FROM `mysql`.`proc` WHERE `db` = '" & Database & "'" + modMain.$hResult = modMain.$Connection.Exec(modMain.$Query) For Each modMain.$hResult asRoutines.Add(modMain.$hResult!name) Next @@ -129,14 +134,16 @@ End Public Function Charset(Optional Database As String) As String If Not Database Then Database = modMain.$Connection.Name - Return modMain.$Connection.Exec("SELECT `DEFAULT_CHARACTER_SET_NAME` FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME` = '" & Database & "'")!DEFAULT_CHARACTER_SET_NAME + modMain.$Query = "SELECT `DEFAULT_CHARACTER_SET_NAME` FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME` = '" & Database & "'" + Return modMain.$Connection.Exec(modMain.$Query)!DEFAULT_CHARACTER_SET_NAME End Public Function Collation(Optional Database As String) As String If Not Database Then Database = modMain.$Connection.Name - Return modMain.$Connection.Exec("SELECT `DEFAULT_COLLATION_NAME` FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME` = '" & Database & "'")!DEFAULT_COLLATION_NAME + modMain.$Query = "SELECT `DEFAULT_COLLATION_NAME` FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME` = '" & Database & "'" + Return modMain.$Connection.Exec(modMain.$Query)!DEFAULT_COLLATION_NAME End diff --git a/gb.db.mysql/src/gb.db.mysql/_Field.class b/gb.db.mysql/src/gb.db.mysql/_Field.class index 3f9418ff5..89362efeb 100644 --- a/gb.db.mysql/src/gb.db.mysql/_Field.class +++ b/gb.db.mysql/src/gb.db.mysql/_Field.class @@ -54,7 +54,8 @@ End Public Function Info(Table As String, Field As String, Optional Database As String) As String If Not Database Then Database = modMain.$Connection.Name - modMain.$hResult = modMain.$Connection.Exec("SELECT `COLUMN_KEY`, `COLUMN_NAME`, `COLUMN_TYPE`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `EXTRA`, `COLUMN_COMMENT` FROM `information_schema`.`COLUMNS` WHERE `TABLE_NAME` = '" & Table & "' AND `TABLE_SCHEMA` = '" & Database & "' AND `COLUMN_NAME` = '" & Field & "'") + modMain.$Query = "SELECT `COLUMN_KEY`, `COLUMN_NAME`, `COLUMN_TYPE`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `EXTRA`, `COLUMN_COMMENT` FROM `information_schema`.`COLUMNS` WHERE `TABLE_NAME` = '" & Table & "' AND `TABLE_SCHEMA` = '" & Database & "' AND `COLUMN_NAME` = '" & Field & "'" + modMain.$hResult = modMain.$Connection.Exec(modMain.$Query) $sTmp &= "Field: " & modMain.$hResult!COLUMN_NAME & GB.NewLine $sTmp &= "Type: " & modMain.$hResult!COLUMN_TYPE & GB.NewLine $sTmp &= "Null: " & modMain.$hResult!IS_NULLABLE & GB.NewLine @@ -69,7 +70,8 @@ End Public Function Definition(Table As String, Field As String, Optional Database As String) As String If Not Database Then Database = modMain.$Connection.Name - modMain.$hResult = modMain.$Connection.Exec("SELECT `COLUMN_TYPE`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `EXTRA`, `COLUMN_COMMENT` FROM `information_schema`.`COLUMNS` WHERE `TABLE_NAME` = '" & Table & "' AND `TABLE_SCHEMA` = '" & Database & "' AND `COLUMN_NAME` = '" & Field & "'") + modMain.$Query = "SELECT `COLUMN_TYPE`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `EXTRA`, `COLUMN_COMMENT` FROM `information_schema`.`COLUMNS` WHERE `TABLE_NAME` = '" & Table & "' AND `TABLE_SCHEMA` = '" & Database & "' AND `COLUMN_NAME` = '" & Field & "'" + modMain.$hResult = modMain.$Connection.Exec(modMain.$Query) $sTmp = modMain.$hResult!COLUMN_TYPE If modMain.$hResult!IS_NULLABLE = "NO" Then $sTmp &= " NOT NULL" If modMain.$hResult!COLUMN_DEFAULT Then $sTmp &= " DEFAULT " & modMain.$hResult!COLUMN_DEFAULT @@ -82,6 +84,7 @@ 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(Table, Field, Database)) + modMain.$Query = "ALTER TABLE `" & Database & "`.`" & Table & "` CHANGE COLUMN `" & Field & "` `" & NewField & "` " & Definition(Table, Field, Database) + modMain.$Connection.Exec(modMain.$Query) End diff --git a/gb.db.mysql/src/gb.db.mysql/_MySQL.class b/gb.db.mysql/src/gb.db.mysql/_MySQL.class index 34d284bd3..0a90004ca 100644 --- a/gb.db.mysql/src/gb.db.mysql/_MySQL.class +++ b/gb.db.mysql/src/gb.db.mysql/_MySQL.class @@ -159,7 +159,8 @@ End Public Function CurrentTimestamp(Optional {Format} As String) As String If Not {Format} Then {Format} = "yyyy-mm-dd hh:nn:ss" - Return Format(modMain.$Connection.Exec("SELECT CURRENT_TIMESTAMP")!CURRENT_TIMESTAMP, {Format}) + modMain.$Query = "SELECT CURRENT_TIMESTAMP" + Return Format(modMain.$Connection.Exec(modMain.$Query)!CURRENT_TIMESTAMP, {Format}) End @@ -172,7 +173,8 @@ End Private Function Collations_Read() As String[] $asCollations.Clear() - modMain.$hResult = modMain.$Connection.Exec("SELECT `COLLATION_NAME` FROM `information_schema`.`COLLATIONS` ORDER BY `COLLATION_NAME`") + modMain.$Query = "SELECT `COLLATION_NAME` FROM `information_schema`.`COLLATIONS` ORDER BY `COLLATION_NAME`" + modMain.$hResult = modMain.$Connection.Exec(modMain.$Query) For Each modMain.$hResult $asCollations.Add(modMain.$hResult["COLLATION_NAME"]) modMain.$hResult.MoveNext() @@ -184,7 +186,8 @@ End Private Function Engines_Read() As String[] $asEngines.Clear() - modMain.$hResult = modMain.$Connection.Exec("SHOW ENGINES") + modMain.$Query = "SHOW ENGINES" + modMain.$hResult = modMain.$Connection.Exec(modMain.$Query) For Each modMain.$hResult $asEngines.Add(modMain.$hResult["Engine"]) modMain.$hResult.MoveNext() @@ -196,7 +199,8 @@ End Private Function Charsets_Read() As String[] $asCharsets.Clear() - modMain.$hResult = modMain.$Connection.Exec("SELECT DISTINCT `CHARACTER_SET_NAME` FROM `information_schema`.`COLLATIONS` ORDER BY `CHARACTER_SET_NAME`") + modMain.$Query = "SELECT DISTINCT `CHARACTER_SET_NAME` FROM `information_schema`.`COLLATIONS` ORDER BY `CHARACTER_SET_NAME`" + modMain.$hResult = modMain.$Connection.Exec(modMain.$Query) For Each modMain.$hResult $asCharsets.Add(modMain.$hResult["CHARACTER_SET_NAME"]) modMain.$hResult.MoveNext() @@ -215,7 +219,8 @@ End Private Function Databases_Read() As String[] $asDatabases.Clear() - modMain.$hResult = modMain.$Connection.Exec("SHOW DATABASES") + modMain.$Query = "SHOW DATABASES" + modMain.$hResult = modMain.$Connection.Exec(modMain.$Query) For Each modMain.$hResult $asDatabases.Add(modMain.$hResult["Database"]) modMain.$hResult.MoveNext() @@ -227,7 +232,8 @@ End Private Function Users_Read() As String[] $asUsers.Clear() - modMain.$hResult = modMain.$Connection.Exec("SELECT DISTINCT `User` FROM `mysql`.`user`") + modMain.$Query = "SELECT DISTINCT `User` FROM `mysql`.`user`" + modMain.$hResult = modMain.$Connection.Exec(modMain.$Query) For Each modMain.$hResult $asUsers.Add(modMain.$hResult["User"]) modMain.$hResult.MoveNext() @@ -238,7 +244,8 @@ End Public Procedure Use(Database As String) - modMain.$Connection.Exec("USE `" & Database & "`") + modMain.$Query = "USE `" & Database & "`" + modMain.$Connection.Exec(modMain.$Query) modMain.$Connection.Name = Database End diff --git a/gb.db.mysql/src/gb.db.mysql/_Routines.class b/gb.db.mysql/src/gb.db.mysql/_Routines.class index 34dbc6183..866bee865 100644 --- a/gb.db.mysql/src/gb.db.mysql/_Routines.class +++ b/gb.db.mysql/src/gb.db.mysql/_Routines.class @@ -48,9 +48,11 @@ Public Function Info(Routine As String, Optional Database As String) As String If Not modMain.$hResult.Available Then Return Select (modMain.$hResult!TYPE) Case "FUNCTION" - Return modMain.$Connection.Exec("SHOW CREATE FUNCTION `" & Database & "`.`" & Routine & "`")!"Create Function" + modMain.$Query = "SHOW CREATE FUNCTION `" & Database & "`.`" & Routine & "`" + Return modMain.$Connection.Exec(modMain.$Query)!"Create Function" Case "PROCEDURE" - Return modMain.$Connection.Exec("SHOW CREATE PROCEDURE `" & Database & "`.`" & Routine & "`")!"Create Procedure" + modMain.$Query = "SHOW CREATE PROCEDURE `" & Database & "`.`" & Routine & "`" + Return modMain.$Connection.Exec(modMain.$Query)!"Create Procedure" Default End Select @@ -59,6 +61,7 @@ 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 + modMain.$Query = "SELECT `body` FROM `mysql`.`proc` WHERE `db` = '" & Database & "' AND `name` = '" & Routine & "'" + Return modMain.$Connection.Exec(modMain.$Query)["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 e31aa61fc..193a2d69d 100644 --- a/gb.db.mysql/src/gb.db.mysql/_Table.class +++ b/gb.db.mysql/src/gb.db.mysql/_Table.class @@ -64,7 +64,8 @@ End Public Function Info(Table As String) As String - Return modMain.$Connection.Exec("SHOW CREATE TABLE `" & Table & "`")!"Create Table" + modMain.$Query = "SHOW CREATE TABLE `" & Table & "`" + Return modMain.$Connection.Exec(modMain.$Query)!"Create Table" End @@ -107,7 +108,8 @@ Public Function Fields(Table As String, Optional Database As String) As String[] Dim asFields As New String[] If Not Database Then Database = modMain.$Connection.Name - modMain.$hResult = modMain.$Connection.Exec("SHOW COLUMNS FROM `" & Database & "`.`" & Table & "`") + modMain.$Query = "SHOW COLUMNS FROM `" & Database & "`.`" & Table & "`" + modMain.$hResult = modMain.$Connection.Exec(modMain.$Query) For Each modMain.$hResult asFields.Add(modMain.$hResult!Field) Next @@ -118,21 +120,24 @@ 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 + modMain.$Query = "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`" + Return modMain.$Connection.Exec(modMain.$Query)!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 + modMain.$Query = "SELECT `TABLE_COLLATION` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = '" & Database & "' AND `TABLE_NAME` = '" & Table & "'" + Return modMain.$Connection.Exec(modMain.$Query)!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 + modMain.$Query = "SELECT `ENGINE` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = '" & Database & "' AND `TABLE_NAME` = '" & Table & "'" + Return modMain.$Connection.Exec(modMain.$Query)!ENGINE End diff --git a/gb.db.mysql/src/gb.db.mysql/_Trigger.class b/gb.db.mysql/src/gb.db.mysql/_Trigger.class index 450a88429..7ec77070f 100644 --- a/gb.db.mysql/src/gb.db.mysql/_Trigger.class +++ b/gb.db.mysql/src/gb.db.mysql/_Trigger.class @@ -29,7 +29,8 @@ End Public Function Info(Trigger As String, Optional Database As String) As String If Not Database Then Database = modMain.$Connection.Name - Return modMain.$Connection.Exec("SELECT `ACTION_STATEMENT` FROM `information_schema`.`TRIGGERS` WHERE `TRIGGER_SCHEMA` = '" & Database & "' AND `TRIGGER_NAME` = '" & Trigger & "'")!ACTION_STATEMENT + modMain.$Query = "SELECT `ACTION_STATEMENT` FROM `information_schema`.`TRIGGERS` WHERE `TRIGGER_SCHEMA` = '" & Database & "' AND `TRIGGER_NAME` = '" & Trigger & "'" + Return modMain.$Connection.Exec(modMain.$Query)!ACTION_STATEMENT End diff --git a/gb.db.mysql/src/gb.db.mysql/_User.class b/gb.db.mysql/src/gb.db.mysql/_User.class index 018c1357f..a6dda85d6 100644 --- a/gb.db.mysql/src/gb.db.mysql/_User.class +++ b/gb.db.mysql/src/gb.db.mysql/_User.class @@ -16,7 +16,8 @@ End Public Procedure Add(User As String, Password As String, Host As String) - modMain.$Connection.Exec("CREATE USER '" & User & "'@'" & Host & "' IDENTIFIED BY '" & Password & "'") + modMain.$Query = "CREATE USER '" & User & "'@'" & Host & "' IDENTIFIED BY '" & Password & "'" + modMain.$Connection.Exec(modMain.$Query) End @@ -38,10 +39,12 @@ Public Function Info(User As String) As String Dim sDefinition As String 'Validate if mysql.user_info exists - modMain.$hResult = modMain.$Connection.Exec("SELECT * FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = 'mysql' AND `TABLE_NAME` = 'user_info'") + modMain.$Query = "SELECT * FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = 'mysql' AND `TABLE_NAME` = 'user_info'" + modMain.$hResult = modMain.$Connection.Exec(modMain.$Query) If Not modMain.$hResult.Available Then Return "" - modMain.$hResult = modMain.$Connection.Exec("SELECT * FROM `mysql`.`user_info` WHERE `User` = '" & User & "'") + modMain.$Query = "SELECT * FROM `mysql`.`user_info` WHERE `User` = '" & User & "'" + modMain.$hResult = modMain.$Connection.Exec(modMain.$Query) sDefinition &= "User: " & modMain.$hResult!User & GB.NewLine sDefinition &= "Name: " & modMain.$hResult!Full_name & GB.NewLine sDefinition &= "Description: " & modMain.$hResult!Description & GB.NewLine diff --git a/gb.db.mysql/src/gb.db.mysql/_View.class b/gb.db.mysql/src/gb.db.mysql/_View.class index f5d7da1df..e46b605eb 100644 --- a/gb.db.mysql/src/gb.db.mysql/_View.class +++ b/gb.db.mysql/src/gb.db.mysql/_View.class @@ -33,13 +33,15 @@ End Public Function Info(View As String, Optional Database As String) As String If Not Database Then Database = modMain.$Connection.Name - Return modMain.$Connection.Exec("SHOW CREATE VIEW `" & Database & "`.`" & View & "`")!"Create View" + modMain.$Query = "SHOW CREATE VIEW `" & Database & "`.`" & View & "`" + Return modMain.$Connection.Exec(modMain.$Query)!"Create View" End Public Function Definition(View As String, Optional Database As String) As String If Not Database Then Database = modMain.$Connection.Name - Return modMain.$Connection.Exec("SELECT `VIEW_DEFINITION` FROM `information_schema`.`VIEWS` WHERE `TABLE_SCHEMA` = '" & Database & "' AND `TABLE_NAME` = '" & View & "'")!"VIEW_DEFINITION" + modMain.$Query = "SELECT `VIEW_DEFINITION` FROM `information_schema`.`VIEWS` WHERE `TABLE_SCHEMA` = '" & Database & "' AND `TABLE_NAME` = '" & View & "'" + Return modMain.$Connection.Exec(modMain.$Query)!"VIEW_DEFINITION" -End \ No newline at end of file +End