|
本帖最后由 liufenglg 于 2010-10-6 16:34 编辑 #include <SQLite.au3>
#include <SQLite.dll.au3>
#include <file.au3>
#include <array.au3>
_SQLite_Startup()
;Filenames
Local $sTsvFile = FileGetShortName(_TempFile(@ScriptDir,"~",".exe"))
Local $sDbFile = FileGetShortName(_TempFile(@ScriptDir,"~",".db"))
;Create Tsv File
FileWriteLine($sTsvFile,"a" & @TAB & "b" & @TAB & "c")
FileWriteLine($sTsvFile,"a1" & @TAB & "b1" & @TAB & "c1")
FileWriteLine($sTsvFile,"a2" & @TAB & "b2" & @TAB & "c2")
MsgBox(0,'',FileRead($sTsvFile))
;import (using SQLite3.exe)
Local $sIn,$sOut,$i, $sCreate = "CREATE TABLE TblImport (";
for $i = 1 To _StringCountOccurance(FileReadLine($sTsvFile,1),@TAB) + 1
$sCreate &= "Column_" & $i & ","
Next
MsgBox(0,'$sCreate',$sCreate)
MsgBox(0,'_StringCountOccurance(FileReadLine($sTsvFile,1),@TAB)',_StringCountOccurance(FileReadLine($sTsvFile,1),@TAB))
$sCreate = StringTrimRight($sCreate,1) & ");"
MsgBox(0,'$sCreate',$sCreate)
$sIn = $sCreate & @CRLF ; Create Table
$sIn &= ".separator \t" & @CRLF ; Select @TAB as Separator
$sIn &= ".import '" & $sTsvFile & "' TblImport" & @CRLF
MsgBox(0,'$sCreate',$sIn)
_SQLite_SQLiteExe($sDbFile,$sIn,$sOut,-1,true)
If @error = 0 Then
;Show Table (using SQLite3.dll)
Local $iRows,$iColumns,$aRes
;_SQLite_Startup()
ConsoleWrite("_SQLite_LibVersion=" &_SQLite_LibVersion() & @CRLF)
_SQLite_Open($sDbFile)
_SQLite_GetTable2d(-1,"SELECT ROWID,* FROM TblImport;",$aRes,$iRows,$iColumns)
_SQLite_Display2DResult($aRes) ; Output to Console
_ArrayDisplay($aRes)
_SQLite_Close()
_SQLite_Shutdown()
Else
If @error = 2 Then
ConsoleWrite("ERROR: Sqlite3.exe file not found" & @CRLF)
Else
ConsoleWrite("ERROR: @error=" & @error & " when calling _SQLite_SQLiteExe" & @CRLF)
EndIf
EndIf
;Remove Temp Files
FileDelete($sTsvFile)
FileDelete($sDbFile)
;~ Output:
;~ rowid Column_1 Column_2 Column_3
;~ 1 a b c
;~ 2 a1 b1 c1
;~ 3 a2 b2 c2
Func _StringCountOccurance($sSearchString,$sSubString,$fCaseSense = 0) ; Returns Number of $sSubString in $sSearchString
Local $iOccCnt = 1
Do
If StringInStr($sSearchString,$sSubString,$fCaseSense,$iOccCnt) > 0 Then
$iOccCnt += 1
Else
ExitLoop
EndIf
Until 0
Return $iOccCnt - 1
EndFunc
请问这里所用的语句
CREATE TABLE TblImport (Column_1,Column_2,Column_3);
.separator \t ;分离器 ??
.import 'D:\au3\~hjnutet.txt' TblImport;;;;;;;;;;;;;;导入数据??
后两行怎么解释啊 |
|