· 7 years ago · Nov 26, 2018, 10:32 AM
1;copy the top header columns. save as C:\import.csv and it will build the needed SQL to import
2
3While 1
4 $nMsg = GUIGetMsg()
5 Switch $nMsg
6 Case $cTooltipClick
7 $clipBoardContents = ClipGet()
8 $array1 = StringExplode($clipBoardContents, @TAB, 0)
9 $cols = ""
10 $tableDef = "DROP TABLE IF EXISTS `development`.`import_tmp`; " & @CRLF & @CRLF & "CREATE TABLE `development`.`import_tmp` ("
11 For $i = 0 to UBound($array1)-1
12 If $i > 0 Then
13 $comma = ","
14 If ($i = (UBound($array1)-1)) Then
15 $comma = ""
16 EndIf
17 $escCol = "`" & StringStripWS ($array1[$i],3) & "`"
18 $tableDef = $tableDef & @CRLF & @TAB & $escCol & " mediumtext NOT NULL" & $comma
19 $cols = $cols & $escCol & $comma
20 EndIf
21 Next
22 $tableDef = $tableDef & @CRLF & ") ENGINE=InnoDB DEFAULT CHARSET=latin1;" & @CRLF & @CRLF & @CRLF
23 $tableDef = $tableDef & @CRLF & "ALTER TABLE `development`.`import_tmp` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;" & @CRLF & @CRLF & @CRLF
24 $tableDef = $tableDef & "LOAD DATA LOCAL INFILE 'C:\\import.csv' INTO TABLE development.import_tmp FIELDS TERMINATED BY ',' ENCLOSED BY '" & '' & "' LINES TERMINATED BY '\r\n' (" & $cols & ");"
25
26 $tableDef = $tableDef & @CRLF & "DELETE FROM `development`.`import_tmp` WHERE `id` = 1;" & @CRLF & @CRLF & @CRLF
27
28 ClipPut($tableDef)
29 MsgBox("","Copied To Clip",$tableDef)
30 EndSwitch
31 $title = WinGetTitle("[active]")
32
33 if StringInStr($title,"Microsoft Excel") And _IsPressed(11) And _IsPressed(43) Then
34 Send("{CTRLDOWN}c{CTRLUP}")
35 GUISetState(@SW_SHOW)
36 TrayTip("Clear", "", 1)
37 TrayTip("Create MYSQL Table Definiton?", "Create MYSQL Table Definiton?", 5, 1)
38 EndIf
39WEnd
40
41
42
43Func StringExplode($sString, $sDelimiter, $sLimit = 0)
44 If $sLimit > 0 Then
45 ;Replace delimiter with NULL character using given limit
46 $sString = StringReplace($sString,$sDelimiter,Chr(0),$sLimit)
47
48 ;Split on NULL character, this will leave the remainder in the last element
49 $sDelimiter = Chr(0)
50 ElseIf $sLimit < 0 Then
51 ;Find delimiter occurence from right-to-left
52 $iIndex = StringInStr($sString,$sDelimiter,0,$sLimit)
53
54 If $iIndex Then
55 ;Split on left side of string only
56 $sString = StringLeft($sString,$iIndex-1)
57 EndIf
58 EndIf
59
60 Return StringSplit($sString,$sDelimiter,1)
61EndFunc