Jump to content

Need some guidance with SQL Lite


Trax
 Share

Recommended Posts

   I wrote a script long ago using SQL Lite. It was my first and last and I will be the first to admin my SQL skills are lacking. I simply needed to add a column to an existing table. I went in to the DB Browser and did a "Modify Table" and added the field "Limit". I thought it would be a simple change at that point to add the field to the insert statement but it keeps throwing an error. Any ideas on what I need to do?

Table.thumb.PNG.7a5cda8184aed66720aa1647b19f7f8a.PNG859237881_ModifyTable.thumb.PNG.2ba87bdadd6e36672ae4dec364d7f386.PNG

Insert.PNG

Link to comment
Share on other sites

What is the error text or code?

Your table has a problem: the PK column is defined as INT but that should be INTEGER. SQLite treats PKs differently INT vs INTEGER.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Result of the call was 1 with an @error of -1. Not much help I am afraid. When I initially inserted the column the DB Browser made it "INTEGER" and I changed it to INT so it would match the other fields. My initial create statement was: "CREATE TABLE If not exists BaghouseTemps(Baghouse INT, Stamp CHAR, AvgTemp INT, Limit INT, Exceeded CHAR, GoodReadings INT, ErrorReadings INT, Id INT PRIMARY KEY);"

 

I thought INT was just short for INTEGER. Obviously not. So is it just a matter of leaving the inserted column as "INTEGER"?

 

 

Link to comment
Share on other sites

Please post your code.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=SRT.ico
#AutoIt3Wrapper_Outfile=IDEM.exe
#AutoIt3Wrapper_Res_Comment=
#AutoIt3Wrapper_Res_Description=
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
AutoItSetOption("MouseCoordMode", 1) ; 0=Relative to Active Window, 1=Absolute Screen 2=Relitive to Client Area
AutoItSetOption("GUICloseOnESC", 1) ; Close on ESC
#include-once
Opt("TrayMenuMode", 1)
OnAutoItExitRegister("Quit")

#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <CommInterface.au3>
#include <GuiListBox.au3>
#include <Date.au3>
#include <SQLite.au3>
#include <File.au3>

#Region ### START Koda GUI section ### Form=f:\companyshared\customers\srt aluminum\rs485\idem\koda_1.7.2.0\forms\limits.kxf
$Limits = GUICreate("Limits", 202, 189, 996, 129)
$LimitsLabel1 = GUICtrlCreateLabel("Baghouse 1 Limit: ", 16, 24, 91, 17)
$LimitsLabel2 = GUICtrlCreateLabel("Baghouse 2 Limit: ", 16, 64, 91, 17)
$LimitsLabel3 = GUICtrlCreateLabel("Baghouse 3 Limit: ", 16, 104, 91, 17)
$LimitsLabel4 = GUICtrlCreateLabel("Baghouse 4 Limit: ", 16, 144, 91, 17)
$LimitsList1 = GUICtrlCreateList("", 120, 24, 65, 19)
$LimitsList2 = GUICtrlCreateList("", 120, 62, 65, 19)
$LimitsList3 = GUICtrlCreateList("", 120, 104, 65, 19)
$LimitsList4 = GUICtrlCreateList("", 120, 144, 65, 19)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

#Region ### START Koda GUI section ### Form=c:\users\jimbecher\desktop\idem v2.0\koda_1.7.2.0\forms\idem.kxf
$IDEMCollection = GUICreate("Baghouse Temperature Collection V2.00", 755, 504, 226, 126)
$Label1 = GUICtrlCreateLabel(" 3 Hr Avg Temp:", 104, 24, 82, 17)
$List1 = GUICtrlCreateList("", 184, 24, 57, 19)
$Label2 = GUICtrlCreateLabel("Limit Exceeded:", 280, 24, 79, 17)
$Label3 = GUICtrlCreateLabel("Good Readings:", 416, 24, 81, 17)
$List3 = GUICtrlCreateList("", 496, 24, 57, 19)
$Label4 = GUICtrlCreateLabel("Error Readings:", 592, 24, 77, 17)
$List4 = GUICtrlCreateList("", 672, 24, 57, 19)
$List2 = GUICtrlCreateList("", 360, 24, 17, 19)
$Label6 = GUICtrlCreateLabel("1 Min Reading:", 104, 56, 76, 17)
$List5 = GUICtrlCreateList("", 184, 56, 57, 19)
$Label8 = GUICtrlCreateLabel("Error:", 464, 56, 29, 17)
$List7 = GUICtrlCreateList("", 496, 56, 17, 19)
$Label7 = GUICtrlCreateLabel("Limit Exceeded:", 280, 56, 79, 17)
$List6 = GUICtrlCreateList("", 360, 56, 17, 19)
$Label5 = GUICtrlCreateLabel("Baghouse 1", 32, 24, 61, 17)
$Label9 = GUICtrlCreateLabel("3 Hr Avg Temp:", 104, 112, 79, 17)
$List8 = GUICtrlCreateList("", 184, 112, 57, 19)
$Label10 = GUICtrlCreateLabel("Limit Exceeded:", 280, 112, 79, 17)
$List9 = GUICtrlCreateList("", 361, 112, 15, 19)
$Label11 = GUICtrlCreateLabel("Good Readings:", 408, 112, 81, 17)
$List10 = GUICtrlCreateList("", 496, 112, 57, 19)
$Label12 = GUICtrlCreateLabel("Error Readings:", 592, 112, 77, 17)
$List11 = GUICtrlCreateList("", 672, 112, 57, 19)
$Label13 = GUICtrlCreateLabel("Baghouse 2", 32, 112, 61, 17)
$Label14 = GUICtrlCreateLabel("1 Min Reading:", 104, 144, 76, 17)
$List12 = GUICtrlCreateList("", 184, 144, 57, 19)
$Label15 = GUICtrlCreateLabel("Limit Exceeded:", 280, 144, 79, 17)
$List13 = GUICtrlCreateList("", 360, 144, 17, 19)
$Label16 = GUICtrlCreateLabel("Error:", 456, 144, 29, 17)
$List14 = GUICtrlCreateList("", 496, 144, 17, 19)
$Label17 = GUICtrlCreateLabel("3 Hr Avg Temp:", 104, 200, 79, 17)
$List15 = GUICtrlCreateList("", 184, 200, 57, 19)
$Label18 = GUICtrlCreateLabel("Limit Exceeded:", 280, 200, 79, 17)
$List16 = GUICtrlCreateList("", 360, 200, 17, 19)
$Label19 = GUICtrlCreateLabel("Good Readings:", 416, 200, 81, 17)
$List17 = GUICtrlCreateList("", 496, 200, 57, 19)
$Label20 = GUICtrlCreateLabel("Error Readings:", 592, 200, 77, 17)
$List18 = GUICtrlCreateList("", 672, 200, 57, 19)
$Label21 = GUICtrlCreateLabel("Baghouse 3", 32, 200, 61, 17)
$Label22 = GUICtrlCreateLabel("1 Min Reading:", 104, 232, 76, 17)
$List19 = GUICtrlCreateList("", 184, 232, 57, 19)
$Label23 = GUICtrlCreateLabel("Limit Exceeded:", 280, 232, 79, 17)
$List20 = GUICtrlCreateList("", 360, 232, 17, 19)
$Label24 = GUICtrlCreateLabel("Error:", 464, 232, 29, 17)
$List21 = GUICtrlCreateList("", 496, 232, 17, 19)
$List29 = GUICtrlCreateList("", 184, 368, 545, 19)
$Label33 = GUICtrlCreateLabel("Status:", 144, 368, 37, 17)
$Label34 = GUICtrlCreateLabel("Errors:", 144, 400, 34, 17)
$List30 = GUICtrlCreateList("", 184, 400, 545, 45)
$Label25 = GUICtrlCreateLabel("3 Hr  Avg Temp:", 104, 288, 82, 17)
$List22 = GUICtrlCreateList("", 184, 288, 57, 19)
$Label26 = GUICtrlCreateLabel("Limit Exceeded:", 280, 288, 79, 17)
$List23 = GUICtrlCreateList("", 360, 288, 17, 19)
$Label27 = GUICtrlCreateLabel("Good Readings:", 416, 288, 81, 17)
$List24 = GUICtrlCreateList("", 496, 288, 57, 19)
$Label28 = GUICtrlCreateLabel("Error Readings:", 592, 288, 77, 17)
$List25 = GUICtrlCreateList("", 672, 288, 57, 19)
$Label29 = GUICtrlCreateLabel("Baghouse 4", 32, 288, 61, 17)
$Label30 = GUICtrlCreateLabel("1 Min Reading:", 104, 320, 76, 17)
$List26 = GUICtrlCreateList("", 184, 320, 57, 19)
$Label31 = GUICtrlCreateLabel("Limit Exceeded:", 280, 320, 79, 17)
$List27 = GUICtrlCreateList("", 360, 320, 17, 19)
$Label32 = GUICtrlCreateLabel("Error:", 464, 320, 29, 17)
$List28 = GUICtrlCreateList("", 496, 320, 17, 19)
$Label35 = GUICtrlCreateLabel("Time Elapsed:", 112, 456, 71, 17)
$List31 = GUICtrlCreateList("", 184, 456, 145, 19)
$Label36 = GUICtrlCreateLabel("Save Cycles:", 560, 456, 66, 17)
$List32 = GUICtrlCreateList("", 624, 456, 105, 19)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $Debug = False, $ErrorCode
Global $NumBaghouses = 4
Global $PeriodAvgTemp[$NumBaghouses + 1], $PeriodLimitExceeded[$NumBaghouses + 1], $PeriodGoodReadings[$NumBaghouses + 1], $PeriodErrorReadings[$NumBaghouses + 1]
Global $ComPort = 36, $Baud = 9600, $Databits = 7, $Parity = "O", $Stopbits = 1
Global $ReadTimeout = 10000, $ComError, $SleepAfterSend = 1000
Global $CurTemp = 0, $CurLE = "N", $CurError = "N", $ReadCount = 0, $SaveCount = 0
Global $StartTime = _NowCalc(), $CycleStart
Global $ReadingsEvery = 60  ; Seconds - How often to take a reading
Global $StoreEvery    = 2 ; Store every X readings - One per minute for three hours
Global $BHLimit[5]
Global $IsErrorFatal = "No", $ErrorTitle = "", $ErrorMessage = ""
Local Const $ExplicitIniName = "IDEM.ini"
Local Const $SQLITE_DLL = "sqlite3.dll"
Local Const $SQLITE_Database_Name = "IDEM.sql"
Local $hDB, $Index, $LogDetail

Readini()
For $Index = 30 to 1 Step -1
    ShowStatus("Initializing. Please wait: " & $Index)
    Sleep(1000)
Next

_SQLite_Startup($SQLITE_DLL, False, 1)
If @error Then
    MsgBox($MB_ICONERROR, "SQLite Startup Error", "Unable to start SQLite. Check existence of DLL")
    Quit()
EndIf

AdlibRegister(CheckQuit, 15000)
$hDB = _SQLite_Open($SQLITE_Database_Name)
If $hDB = 0 Then
    MsgBox(0, "SQLite Open Error", "Unable to open " & $SQLITE_Database_Name)
    Exit
EndIf

InitPeriod()
MyListBoxUpdate($List32, $SaveCount)
UpdateRuntime()
While 1
    $CycleStart = _NowCalc()
    $ReadCount = $ReadCount + 1
    For $Index = 1 To $NumBaghouses
        $Debug = FileExists("Debug.txt")
        ReadMeter($Index)
        Calculate($Index)
        RefreshDisplay($Index)
        UpdateRuntime()
    Next
    If $ReadCount = $StoreEvery Then
        SaveData()
        InitPeriod()
        UpdateRuntime()
    EndIf
    Wait()
WEnd

Func CheckQuit()
    If FileExists("QuitIDEM.txt") = 0 Then
        Return
    EndIf
Quit()
EndFunc

Func Quit()
    _SQLite_Close()
    _SQLite_Shutdown()
    Exit
EndFunc

Func SaveData()
    ShowDebug("Entering function SaveData()")
    Local $SrtCount, $sSQL, $Index
    Local $StdStr = "INSERT INTO BaghouseTemps(Baghouse,Stamp,AvgTemp,Limit,Exceeded,GoodReadings,ErrorReadings) VALUES("
    For $Index = 1 to $NumBaghouses
        $sSQL = $StdStr & $Index & ",'" & _NowCalc() & "'," & $PeriodAvgTemp[$Index] & "," & $BHLimit[$Index] & ",'" & $PeriodLimitExceeded[$Index] & "'," & $PeriodGoodReadings[$Index] & "," & $PeriodErrorReadings[$Index] & ");"
        $Result = _SQLite_Exec(-1, $sSQL)
        If $Result <> $SQLITE_OK Then
            MsgBox(0, "SQLite Log Data Error", "Result: " & $Result & "    @error: " & @error)
            MsgBox(0,"Pass: " & $Index,$sSQL)
        Quit()
        EndIf
    Next
    $SaveCount = $SaveCount + 1
    $StrCount = $SaveCount
    $StrCount = _StringAddThousandsSep($StrCount)
    MyListBoxUpdate($List32, $StrCount)
EndFunc

Func Wait()
    ShowDebug("Entering Function Wait()")
    Local $TimeDiff, $Mins, $Secs
    While 1
        $TimeDiff = $ReadingsEvery - _DateDiff("s", $CycleStart, _NowCalc())
        If $TimeDiff <= 0 Then
            ExitLoop
        EndIf
        $Mins = Floor($TimeDiff / 60)
        $Secs = Floor($TimeDiff - (60 * $Mins))
        ShowStatus("Time to next reading: " & $Mins & " Mins, " & $Secs & " Secs")
        Sleep(1000)
    WEnd
EndFunc

Func UpdateRuntime()
    ShowDebug("Entering Function UpdateRunTime()")
    Local $TimeDiff, $StrCount, $Days = 0, $Hours = 0, $Mins = 0
    $TimeDiff = _DateDiff("n", $StartTime, _NowCalc())
    $Days  = Floor($TimeDiff / 1440)
    $Hours = Floor(($TimeDiff - ($Days * 1440)) / 60)
    $Mins  = Floor(($TimeDiff - ($Days * 1440) - ($Hours * 60)))
    MyListBoxUpdate($List31, $Days & " Days, " & $Hours & " Hrs, " & $Mins & " Mins")
    ShowDebug("Exitinging function UpdateRuntime()")
EndFunc

Func InitPeriod()
    ShowDebug("Entering Function InitPeriod()")
    Local $Index
    $ReadingCount = 0
    $CurTemp = 0
    $CurLE = 0
    $CurError = 0
    For $Index = 1 To $NumBaghouses
        $PeriodAvgTemp[$Index] = 0
        $PeriodLimitExceeded[$Index] = "N"
        $PeriodGoodReadings[$Index] = 0
        $PeriodErrorReadings[$Index] = 0
        RefreshDisplay($Index)
    Next
    $ReadCount = 0
    $CurTemp = 0
    $CurLE = 0
    $CurError = 0
EndFunc

Func RefreshDisplay($Baghouse)
    ShowDebug("Entering Function RefreshDisplay() for  Baghouse " & $Baghouse)
    Select
        Case $Baghouse = 1
            MyListBoxUpdate($List1,  $PeriodAvgTemp[$Baghouse])
            MyListBoxUpdate($List2,  $PeriodLimitExceeded[$Baghouse])
            MyListBoxUpdate($List3,  $PeriodGoodReadings[$Baghouse])
            MyListBoxUpdate($List4,  $PeriodErrorReadings[$Baghouse])
            MyListBoxUpdate($List5,  $CurTemp)
            MyListBoxUpdate($List6,  $CurLE)
            MyListBoxUpdate($List7,  $CurError)
        Case $Baghouse = 2
            MyListBoxUpdate($List8,  $PeriodAvgTemp[$Baghouse])
            MyListBoxUpdate($List9,  $PeriodLimitExceeded[$Baghouse])
            MyListBoxUpdate($List10, $PeriodGoodReadings[$Baghouse])
            MyListBoxUpdate($List11, $PeriodErrorReadings[$Baghouse])
            MyListBoxUpdate($List12, $CurTemp)
            MyListBoxUpdate($List13, $CurLE)
            MyListBoxUpdate($List14, $CurError)
        Case $Baghouse = 3
            MyListBoxUpdate($List15, $PeriodAvgTemp[$Baghouse])
            MyListBoxUpdate($List16, $PeriodLimitExceeded[$Baghouse])
            MyListBoxUpdate($List17, $PeriodGoodReadings[$Baghouse])
            MyListBoxUpdate($List18, $PeriodErrorReadings[$Baghouse])
            MyListBoxUpdate($List19, $CurTemp)
            MyListBoxUpdate($List20, $CurLE)
            MyListBoxUpdate($List21, $CurError)
        Case $Baghouse = 4
            MyListBoxUpdate($List22, $PeriodAvgTemp[$Baghouse])
            MyListBoxUpdate($List23, $PeriodLimitExceeded[$Baghouse])
            MyListBoxUpdate($List24, $PeriodGoodReadings[$Baghouse])
            MyListBoxUpdate($List25, $PeriodErrorReadings[$Baghouse])
            MyListBoxUpdate($List26, $CurTemp)
            MyListBoxUpdate($List27, $CurLE)
            MyListBoxUpdate($List28, $CurError)
    EndSelect
EndFunc

Func Calculate($Baghouse)
    ShowDebug("Entering Function CalculateReading() for  Baghouse " & $Baghouse)
    Local $TotalTemperature
    If $ComError = False Then
        $CurLE = CalcExceeded($Baghouse, $CurTemp)
    EndIf
    If $ComError = True Then
        $CurError = "Y"
        $PeriodErrorReadings[$Baghouse] = $PeriodErrorReadings[$Baghouse] + 1
        Return
    EndIf
    $TotalTemperature  = $PeriodAvgTemp[$Baghouse] * $PeriodGoodReadings[$Baghouse]
    $TotalTemperature  = $TotalTemperature + $CurTemp
    $PeriodGoodReadings[$Baghouse] = $PeriodGoodReadings[$Baghouse] + 1
    $PeriodAvgTemp[$Baghouse] =  Round($TotalTemperature/ $PeriodGoodReadings[$Baghouse], 0)
    $PeriodLimitExceeded[$Baghouse] = CalcExceeded($Baghouse, $PeriodAvgTemp[$Baghouse])
EndFunc

Func CalcExceeded($Baghouse, $Temperature)
    ShowDebug("Entering Function CalcExceeded() for  Baghouse " & $Baghouse)
    Select
        Case ($Baghouse = 1) and ($Temperature >= $BHLimit[1])
            Return "Y"
        Case ($Baghouse = 2) and ($Temperature >= $BHLimit[2])
            Return "Y"
        Case ($Baghouse = 3) and ($Temperature >= $BHLimit[3])
            Return "Y"
        Case ($Baghouse = 4) and ($Temperature >= $BHLimit[4])
            Return "Y"
    EndSelect
    Return "N"
EndFunc

Func ReadMeter($Baghouse)
    ShowDebug("Entering Function ReadMeter() for Baghouse " & $Baghouse)
    Local $PortHandle, $ReceiveResult, $SendString
    Local $BytesToSend, $BytesSent, $Meter = 0
    $CurTemp = 0
    $CurLE = "N"
    $CurError = "N"
    $ComError = False
    Select
        Case $Baghouse = 1
            $ComPort = 36
            $Meter = 2
        Case $Baghouse = 2
            $ComPort = 36
            $Meter = 4
        Case $Baghouse = 3
            $ComPort = 36
            $Meter = 6
        Case $Baghouse = 4
            $ComPort = 35
            $Meter = 11
    EndSelect
    ShowStatus("Reading Meter " & $Meter)
    $PortHandle = _CommAPI_OpenCOMPort($ComPort, $Baud, $Parity, $Databits, $StopBits)
    If $PortHandle = 0 Then
        $ErrorCode = @error
        If ($ErrorCode = -1) Then
            $ErrorCode = "X" & _WinAPI_GetLastError()
            EndIf
        ShowError("Error Code: " & $ErrorCode & ", Opening Meter: " & $Meter & ", Comport: " & $ComPort)
        $ComError = True
        _CommAPI_ClosePort($PortHandle)
        Return
    EndIf
    $SendString = "N" & $Meter & "TA$"
    $BytesToSend = StringLen($SendString)
    $BytesSent = _CommAPI_TransmitString($PortHandle, $SendString, 0)
    Sleep($SleepAfterSend)
    If ($BytesSent <> $BytesToSend) Then
        $ErrorCode = @error
        If ($ErrorCode = -1) Then
            $ErrorCode = "X" & _WinAPI_GetLastError()
            EndIf
        ShowError("Error Code: " & $ErrorCode & ", Sent: '" & $SendString & "', On Meter: " & $Meter & ", Comport: " & $ComPort)
        $ComError = True
        _CommAPI_ClosePort($PortHandle)
        Return
    EndIf
    $ReceiveResult = _CommAPI_ReceiveString($PortHandle, $ReadTimeout, 0, "", 0)
    _CommAPI_ClosePort($PortHandle)
    ShowDebug("Received: '" & $ReceiveResult & "' From Meter: " & $Meter & " Comport: " & $ComPort)
    If @error <> 0 Then
        $ErrorCode = @error
        If ($ErrorCode = -1) Then
            $ErrorCode = "X" & _WinAPI_GetLastError()
        EndIf
        $ComError = True
        ShowError("Error Code: " & $ErrorCode & ", Received: '" & $ReceiveResult & "', On Meter: " & $Meter & ", Comport: " & $ComPort)
        Return
    EndIf
    If $ReceiveResult = "" Then
        ShowError("Error Code: N/A , Received: '',  On Meter: " & $Meter & ", Comport: " & $ComPort)
        $ComError = True
        Return
    EndIf
    $CurTemp = StringRight($ReceiveResult, 10)
    $CurTemp = StringStripWS($CurTemp, 8)
    ShowStatus("Successfully read temperature for Baghouse " & $Baghouse)
EndFunc

Func ShowStatus($ShowMessage)
    MyListBoxUpdate($List29, $ShowMessage)
    EndFunc

Func ShowError($ShowMessage)
    _GUICtrlListBox_BeginUpdate($List30)
    _GUICtrlListBox_InsertString($List30, _NowCalc() & ": " & $ShowMessage, 0)
    _GUICtrlListBox_SetCurSel ($List30, 0)
    _GUICtrlListBox_EndUpdate($List30)
EndFunc
Func ShowDebug($ShowMessage)
    If $Debug = False Then
        Return
    EndIf
    MyListBoxUpdate($List29, $ShowMessage)
    Sleep(5000)
EndFunc

Func MyListBoxUpdate($Handle, $ShowValue)
    _GUICtrlListBox_DeleteString($Handle, 0)
    _GUICtrlListBox_AddString($Handle, $ShowValue)
EndFunc

Func _StringAddThousandsSep($sString, $sThousands = ",", $sDecimal = ".")
    Local $aNumber, $sLeft, $sResult = "", $iNegSign = "", $DolSgn = ""
    If Number(StringRegExpReplace($sString, "[^0-9\-.+]", "\1")) < 0 Then $iNegSign = "-" ; Allows for a negative value
    If StringRegExp($sString, "\$") And StringRegExpReplace($sString, "[^0-9]", "\1") <> "" Then $DolSgn = "$" ; Allow for Dollar sign
    $aNumber = StringRegExp($sString, "(\d+)\D?(\d*)", 1)
    If UBound($aNumber) = 2 Then
        $sLeft = $aNumber[0]
        While StringLen($sLeft)
            $sResult = $sThousands & StringRight($sLeft, 3) & $sResult
            $sLeft = StringTrimRight($sLeft, 3)
        WEnd
        $sResult = StringTrimLeft($sResult, 1); Strip leading thousands separator
        If $aNumber[1] <> "" Then $sResult &= $sDecimal & $aNumber[1] ; Add decimal
    EndIf
    Return $iNegSign & $DolSgn & $sResult ; Adds minus or "" (nothing)and Adds $ or ""
EndFunc

; Should have OnAutoItExit Register Set
Func MyError()
Beep()
MsgBox(0, $ErrorTitle, $ErrorMessage)
If $IsErrorFatal = True Then
   Exit
   EndIf
EndFunc

Func Readini()
    Local $NotFound = "Not Found", $Result = 0, $Index = 0, $BlockOption = 0, $DoDebug
    $ErrorTitle = "Error Reading Initialization File"
    $IsErrorFatal = True
    $BHLimit[1] = IniRead($ExplicitIniName, "Limits", "Baghouse1", $NotFound)
    If $BHLimit[1] = $NotFound Then
        $ErrorMessage = "Baghouse1= " & $NotFound
        MyError()
    EndIf
    $BHLimit[1] = Int($BHLimit[1])
    $BHLimit[2] = IniRead($ExplicitIniName, "Limits", "Baghouse2", $NotFound)
    If $BHLimit[2] = $NotFound Then
        $ErrorMessage = "Baghouse2= " & $NotFound
        MyError()
    EndIf
    $BHLimit[2] = Int($BHLimit[2])
    $BHLimit[3] = IniRead($ExplicitIniName, "Limits", "Baghouse3", $NotFound)
    If $BHLimit[3] = $NotFound Then
        $ErrorMessage = "Baghouse3= " & $NotFound
        MyError()
    EndIf
    $BHLimit[3] = Int($BHLimit[3])
    $BHLimit[4] = IniRead($ExplicitIniName, "Limits", "Baghouse4", $NotFound)
    If $BHLimit[4] = $NotFound Then
        $ErrorMessage = "Baghouse4= " & $NotFound
        MyError()
    EndIf
    $BHLimit[4] = Int($BHLimit[4])
    $LogDetail = IniRead($ExplicitIniName, "Settings", "LogDetail", $NotFound)
    If $LogDetail = $NotFound Then
        $ErrorMessage = "LogDetail= " & $NotFound
        MyError()
    EndIf
    If $LogDetail <> "Y" And $LogDetail <> "N" Then
        $ErrorMessage = "LogDetail= must be Y or N not " & $NotFound
        MyError()
    EndIf
    MyListBoxUpdate($LimitsList1, $BHLimit[1])
    MyListBoxUpdate($LimitsList2, $BHLimit[2])
    MyListBoxUpdate($LimitsList3, $BHLimit[3])
    MyListBoxUpdate($LimitsList4, $BHLimit[4])
EndFunc   ;==>Readini

 

Link to comment
Share on other sites

To get detailed error text try to run your script uncompiled and error should be in console output according to sources of Include\SQLite.au3

_SQLite_Exec()

__SQLite_ReportError()

_SQLite_ErrMsg()

__SQLite_Print()

 

EDIT: or add this after _SQLiteExec()

MsgBox(0, "SQLite Error", _SQLite_ErrMsg())

 

Edited by Zedna
Link to comment
Share on other sites

Hey @Trax I believe your problem is with the column name?

Quote

"Modify Table" and added the field "Limit". I thought it would be a simple change at that point to add the field to the insert statement but it keeps throwing an error. Any ideas on what I need to do?

See this link? https://www.sqlite.org/lang_keywords.html

3rd column, 7 from the bottom.

I used DB Browser for SQLite and did this test

insert into tTable (limit) values (1);

Error message

image.png.cacaae7bf784ef19526733e8de013031.png

 

Try renaming the column name to something like "cLimit" -> then SQL will think climit is a valid column name and not confuse it with limit

Local $StdStr = "INSERT INTO BaghouseTemps(Baghouse,Stamp,AvgTemp,cLimit,Exceeded,GoodReadings,ErrorReadings) VALUES("

 

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

Good catch! Why didn't I see the obvious?

@Trax, you can just enclose the column name limit in double quotes or square brackets: "limit" or [limit].

Yes PKs in SQLite is where INT and INTEGER have different meaning. From  https://www.sqlite.org/lang_createtable.html see the following §:

3.5. The PRIMARY KEY

 

5. ROWIDs and the INTEGER PRIMARY KEY

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...