User Tools

Site Tools


vba:access:classes:sqlscript

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
vba:access:classes:sqlscript [24.10.2016 11:32:32]
yaslaw
vba:access:classes:sqlscript [04.09.2019 11:45:59] (current)
yaslaw
Line 1: Line 1:
 <​const>​ <​const>​
-    version=1.5.0  +    version=1.5.4  
-    vdate=21.06.2016+    vdate=04.09.2019
     fname=sqlscript.cls     fname=sqlscript.cls
     ns=%NAMESPACE% ​   ​     ns=%NAMESPACE% ​   ​
Line 95: Line 95:
   * **tdSuppressDashLines** Linien die nur aus -_=| und Leerzeichen bestehen werden unterdrückt. Das werden Trennlinien sein   * **tdSuppressDashLines** Linien die nur aus -_=| und Leerzeichen bestehen werden unterdrückt. Das werden Trennlinien sein
   * **tdDropTable ** Erstelle zum  CREATE TABEL auch ein DROP TABLE   * **tdDropTable ** Erstelle zum  CREATE TABEL auch ein DROP TABLE
 +
 +==== Creatoren ====
 +
 +=== instanceByFileDialog() ===
 +>​Container
 +<​code>​Set container = SQLScript.instanceByFileDialog([filePath])</​code>​
 +Erstellt ein Container aus einer Datei, die mittels dem FileDialog ausgewählt wird
 +<code vb>'/​**
 +' * Erstellt ein DDLScriptcontainer aus einem File, das über den Filedialog ausgewählt wurde
 +' * @example ​   Öffnen des FileDialoges mit direktem ausführen des Codes
 +' *             Call SQLScript.instanceByFileDialog().execute
 +' * @param ​ String ​     Der Pfad/​Dateiname,​ wo der Dialog öffnet
 +' * @retrun SQLScript ​  oder bei Abrruch Nothing
 +' */
 +Public Static Function instanceByFileDialog(Optional ByVal iFilePath As String = Empty) As SQLScript</​code>​
 +
 +=== instanceByFilePath() ===
 +>​Container
 +<​code>​Set container = SQLScript.instanceByFilePath(filePath)</​code>​
 +Erstellt ein Container aus einer Datei. Der Datepafad muss bekannt sein.
 +<code vb>'/​**
 +' * Erstellt ein DDLScriptcontainer aus einem File, das über einen direkten Pfad geöffnet wird
 +' * @example ​   Öffnen und ausführen des ersten SQLs aus einer Date ohne Nachfrage
 +' *             ​SQLScript.instanceByFilePath("​C:​\temp\vba_sql_test.sql"​)(0).execute(spDirect)
 +' * @param ​ String ​     Der Pfad/​Datreiname
 +' * @retrun SQLScript
 +' */
 +Public Static Function instanceByFilePath(ByVal iFilePath As String) As SQLScript</​code>​
 +
 +=== instanceByTableText() ===
 +>​Container
 +<​code>​script = SQLScript.instanceByTableText(text,​ tabellenName [,​Delemiter]</​code>​
 +Diese Methode unterscheidet sich von den Anderen. Die Eingabe ist hier kein SQL, sondern eine Tabelle als Text in einer lesbarer form. Zum Beispiel als CSV
 +<code vb>'/​**
 +' * Erstellt ein DDLScriptcontainer aus einem Text, der eine Tabelle darstellt
 +' * @param ​ String ​         Tabelle in Textform. zB. CSV
 +' * @param ​ String ​         Tabellenname
 +' * @param ​ String ​         Mögliche Spaltendelemiter als RegExp-Pattern
 +' * @param ​ text2ddlParams ​ Steuerparameter
 +' * @param ​ String ​         Eine seperate Kopfzeile. Wenn die Kopfzeile bereits im iText ist,
 +' *                         muss sie nicht seperat mitgegeben werden. NoHeader wird ignoriert
 +' * @retrun SQLScript
 +' */
 +Public Function instanceByTableText( _
 +        ByVal iText As String, _
 +        ByVal iTableName As String, _
 +        Optional ByVal iDelemiterRxPattern As String = "​[,​|;​\t]",​ _
 +        Optional ByVal iParams As text2ddlParams = tdSuppressDashLines,​ _
 +        Optional ByVal iHeader As String = Empty _
 +) As SQLScript</​code>​
 +
 +=== instanceSubScript()===
 +>​Statement
 +<​code>​script = SQLScript.instanceSubScript(command [,​action])</​code>​
 +Erstellt eine Instance für ein einzelnes Script aus einem SQL-Statement heraus.
 +\\ Siehe Beispiel [[#Ein einsames Script erstellen und ausführen]]
 +<code vb>'/​**
 +' * Erstellt eine Instanze eines neuen Subscriptes
 +' * @param ​ String ​         SQL-String
 +' * @param ​ sqlActions ​     Art des Scriptes. Bei -1 wird die Action ermittelt
 +' * @retrun SQLScript
 +' */
 +Public Static Function instanceSubScript(ByVal iCmd As String, Optional ByVal iAction As sqlActions = saAutomatic) As SQLScript</​code>​
  
 ==== Wichtigste Methoden ==== ==== Wichtigste Methoden ====
Line 132: Line 195:
 | saDelete | Long | Anzahl betroffener Zeilen | | saDelete | Long | Anzahl betroffener Zeilen |
 | Else | Long | Boolean | | Else | Long | Boolean |
- 
-=== instanceByFileDialog() === 
->​Container 
-<​code>​Set container = SQLScript.instanceByFileDialog([filePath])</​code>​ 
-Erstellt ein Container aus einer Datei, die mittels dem FileDialog ausgewählt wird 
-<code vb>'/​** 
-' * Erstellt ein DDLScriptcontainer aus einem File, das über den Filedialog ausgewählt wurde 
-' * @example ​   Öffnen des FileDialoges mit direktem ausführen des Codes 
-' *             Call SQLScript.instanceByFileDialog().execute 
-' * @param ​ String ​     Der Pfad/​Dateiname,​ wo der Dialog öffnet 
-' * @retrun SQLScript ​  oder bei Abrruch Nothing 
-' */ 
-Public Static Function instanceByFileDialog(Optional ByVal iFilePath As String = Empty) As SQLScript</​code>​ 
- 
-=== instanceByFilePath() === 
->​Container 
-<​code>​Set container = SQLScript.instanceByFilePath(filePath)</​code>​ 
-Erstellt ein Container aus einer Datei. Der Datepafad muss bekannt sein. 
-<code vb>'/​** 
-' * Erstellt ein DDLScriptcontainer aus einem File, das über einen direkten Pfad geöffnet wird 
-' * @example ​   Öffnen und ausführen des ersten SQLs aus einer Date ohne Nachfrage 
-' *             ​SQLScript.instanceByFilePath("​C:​\temp\vba_sql_test.sql"​)(0).execute(spDirect) 
-' * @param ​ String ​     Der Pfad/​Datreiname 
-' * @retrun SQLScript 
-' */ 
-Public Static Function instanceByFilePath(ByVal iFilePath As String) As SQLScript</​code>​ 
  
 === readFile() === === readFile() ===
Line 178: Line 215:
 ' */ ' */
 Public Sub readText(ByVal iScriptText As String)</​code>​ Public Sub readText(ByVal iScriptText As String)</​code>​
- 
-=== instanceSubScript()=== 
->​Statement 
-<​code>​script = SQLScript.instanceSubScript(command [,​action])</​code>​ 
-Erstellt eine Instance für ein einzelnes Script aus einem SQL-Statement heraus. 
-\\ Siehe Beispiel [[#Ein einsames Script erstellen und ausführen]] 
-<code vb>'/​** 
-' * Erstellt eine Instanze eines neuen Subscriptes 
-' * @param ​ String ​         SQL-String 
-' * @param ​ sqlActions ​     Art des Scriptes. Bei -1 wird die Action ermittelt 
-' * @retrun SQLScript 
-' */ 
-Public Static Function instanceSubScript(ByVal iCmd As String, Optional ByVal iAction As sqlActions = saAutomatic) As SQLScript</​code>​ 
- 
-=== instanceByTableText() === 
->​Container 
-<​code>​script = SQLScript.instanceByTableText(text,​ tabellenName [,​Delemiter]</​code>​ 
-Diese Methode unterscheidet sich von den Anderen. Die Eingabe ist hier kein SQL, sondern eine Tabelle als Text in einer lesbarer form. Zum Beispiel als CSV 
-<code vb>'/​** 
-' * Erstellt ein DDLScriptcontainer aus einem Text, der eine Tabelle darstellt 
-' * @param ​ String ​         Tabelle in Textform. zB. CSV 
-' * @param ​ String ​         Tabellenname 
-' * @param ​ String ​         Mögliche Spaltendelemiter als RegExp-Pattern 
-' * @param ​ text2ddlParams ​ Steuerparameter 
-' * @param ​ String ​         Eine seperate Kopfzeile. Wenn die Kopfzeile bereits im iText ist, 
-' *                         muss sie nicht seperat mitgegeben werden. NoHeader wird ignoriert 
-' * @retrun SQLScript 
-' */ 
-Public Function instanceByTableText( _ 
-        ByVal iText As String, _ 
-        ByVal iTableName As String, _ 
-        Optional ByVal iDelemiterRxPattern As String = "​[,​|;​\t]",​ _ 
-        Optional ByVal iParams As text2ddlParams = tdSuppressDashLines,​ _ 
-        Optional ByVal iHeader As String = Empty _ 
-) As SQLScript</​code>​ 
  
 ==== Wichtigste Properties ==== ==== Wichtigste Properties ====
Line 246: Line 248:
 Der pFad des Scriptfiles. Macht ntürlich auch nur bei einem Containerobjekt Sinn Der pFad des Scriptfiles. Macht ntürlich auch nur bei einem Containerobjekt Sinn
 <code vb>​Public Property Get filePath() As String</​code>​ <code vb>​Public Property Get filePath() As String</​code>​
 +
 +=== script ===
 +Gibt das SQL-SQL-Script zurück. Mit ; am Ende. Im Falle eines Containers wird das ganze Script ausgegeben
 +<code vb>​Public Property Get script() As String</​code>​
  
 ==== verwendete Libraries ==== ==== verwendete Libraries ====
Line 328: Line 334:
  
 Und heir die Umsetzung für ein kleinen Test: Und heir die Umsetzung für ein kleinen Test:
-<code vb> ​   Dim script As SQLScript+<code vb>Sub testSqlScript() 
 +    Dim script As SQLScript
     ​     ​
     Dim txt(5) As String     Dim txt(5) As String
Line 338: Line 345:
     txt(5) = " 4, JKL      ,           , ​           "     txt(5) = " 4, JKL      ,           , ​           "
     ​     ​
-    Set script = SQLScript.instanceByTableText(Join(txt,​ vbCrLf), "​TBL_TEST"​) +    Set script = SQLScript.instanceByTableText(Join(txt,​ vbCrLf), "​TBL_TEST"​, , tdDropTable + tdSuppressDashLines
-    Debug.Print script.toString</​code>​ +    Debug.Print script.script 
-<code sql>​CREATE TABLE [TBL_TEST] ([ID] BYTE,​[ITEM_NAME] TEXT(3),​[ITEM_VALUE] ​TEXT(5),​[CREATE_DATE] DATE) +    script.execute spIgnore 
-INSERT INTO [TBL_TEST] ([ID],​[ITEM_NAME],​[ITEM_VALUE],​[CREATE_DATE]) VALUES (1,'​ABC',​123,#​01-01-1967 00:​00:​00#​) +    Debug.Print script.logText 
-INSERT INTO [TBL_TEST] ([ID],​[ITEM_NAME],​[ITEM_VALUE],​[CREATE_DATE]) VALUES (2,'​DEF',​346.3,#​12-11-2010 00:​00:​00#​) +End Sub</​code>​ 
-INSERT INTO [TBL_TEST] ([ID],​[ITEM_NAME],​[ITEM_VALUE],​[CREATE_DATE]) VALUES (3,'​GHI',​10098,#​11-17-2016 00:​00:​00#​) +<code sql>DROP TABLE [TBL_TEST];​ 
-INSERT INTO [TBL_TEST] ([ID],​[ITEM_NAME],​[ITEM_VALUE],​[CREATE_DATE]) VALUES (4,'​JKL',​NULL,​NULL)</​code>​+CREATE TABLE [TBL_TEST] ([ID] BYTE,​[ITEM_NAME] TEXT(3),​[ITEM_VALUE] ​DOUBLE,​[CREATE_DATE] DATE); 
 +INSERT INTO [TBL_TEST] ([ID],​[ITEM_NAME],​[ITEM_VALUE],​[CREATE_DATE]) VALUES (1,'​ABC',​123,#​01-01-1967 00:00:00#); 
 +INSERT INTO [TBL_TEST] ([ID],​[ITEM_NAME],​[ITEM_VALUE],​[CREATE_DATE]) VALUES (2,'​DEF',​346.3,#​12-11-2010 00:00:00#); 
 +INSERT INTO [TBL_TEST] ([ID],​[ITEM_NAME],​[ITEM_VALUE],​[CREATE_DATE]) VALUES (3,'​GHI',​10098,#​11-17-2016 00:00:00#); 
 +INSERT INTO [TBL_TEST] ([ID],​[ITEM_NAME],​[ITEM_VALUE],​[CREATE_DATE]) VALUES (4,'​JKL',​NULL,​NULL)
 +Table  droped 
 + 
 +Table  created 
 + 
 +Insert ​ rows 
 + 
 +Insert ​ rows 
 + 
 +Insert ​ rows 
 + 
 +Insert ​ rows</​code>​
  
 ==== Script Beispiele ==== ==== Script Beispiele ====
vba/access/classes/sqlscript.1477301552.txt.gz · Last modified: 24.10.2016 11:32:32 by yaslaw