Sign in to follow this  
Followers 0
darzanmihai

SQLite Data Base

5 posts in this topic

I would like to create a database into a folder, and in that data base I would like to create a table with 9 columns.

After the table has been created into the database I whant to insert data Row by row into tha table....could anyone help me with some example script lines?

I have tried something, but i get some errors.

This is the code I tryed:

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\TEO\Desktop\PZU TOTAL ELECTRIC OLTENIA\Consumator-selectie.kxf
            $Form = GUICreate("Prognoza Initiala/Preluare Date/Analiza Contractuala", 653, 447, 411, 216, -1, "", $FormInitial)
            $NumeConsumator = GUICtrlCreateInput("", 24, 32, 313, 25)           
            
            $Label1 = GUICtrlCreateLabel("Numele Consumatorului", 24, 8, 115, 17)
            
            $DetaliiConsumator = GUICtrlCreateGroup("Detalii despre consumator", 8, 64, 625, 350)
            $CentruConsumator = GUICtrlCreateInput("", 28, 118, 273, 21)
            $ZonaLicConsumator = GUICtrlCreateInput("", 28, 174, 273, 21)
            $NrContractTEO = GUICtrlCreateInput("", 340, 118, 273, 21)
            $Label4 = GUICtrlCreateLabel("Numar contract TEO", 340, 94, 102, 17)
            $NrContractConsumator = GUICtrlCreateInput("", 340, 174, 273, 21)
            $Label5 = GUICtrlCreateLabel("Numar contract Consumator", 340, 150, 136, 17)
            $ValabContrDinData = GUICtrlCreateInput("", 148, 246, 153, 21)
            $Label6 = GUICtrlCreateLabel("Valabilitate Contract", 260, 206, 98, 17)
            $Label2 = GUICtrlCreateLabel("Centrul de care apartine consumatorul", 28, 94, 183, 17)
            $Label7 = GUICtrlCreateLabel("Zona de licenta de care apartine consumatorul", 28, 150, 224, 17)
            $ValabContrPanaLaData = GUICtrlCreateInput("", 339, 248, 153, 21)
            $Label3 = GUICtrlCreateLabel("De la data:", 148, 224, 56, 17)
            $Label8 = GUICtrlCreateLabel("Pana la data:", 339, 224, 67, 17)     
            $Label9 = GUICtrlCreateLabel("Valabilitate Anexa 2 din contract", 240, 296, 200, 17)
            $Labe20 = GUICtrlCreateLabel("De la data:", 148, 314, 56, 17)
            $ValabAnexaDinData = GUICtrlCreateInput("", 148, 340, 153, 21);a doua
            $Labe21 = GUICtrlCreateLabel("Pana la data:", 339, 314, 67, 17)
            $ValabAnexaPanaLaData = GUICtrlCreateInput("", 339, 340, 153, 21);a doua
            $AdaugaCons = GUICtrlCreateButton(" Adauga consumator",250,380,153,30)
            
            GUISetState(@SW_SHOW)
            #EndRegion ### START Koda GUI section ### Form=C:\Documents and Settings\TEO\Desktop\PZU TOTAL ELECTRIC OLTENIA\Consumator-selectie.kxf
            Local $aResult, $iRows, $iColumns
            while 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        GUIDelete($Form)
                        ExitLoop
                    Case $AdaugaCons
                        $NumeConsumator1= GUICtrlRead($NumeConsumator)
                        $CentruConsumator1= GUICtrlRead($CentruConsumator)
                        $ZonaLicConsumator1= GUICtrlRead($ZonaLicConsumator)
                        $NrContractTEO1= GUICtrlRead($NrContractTEO)
                        $NrContractConsumator1= GUICtrlRead($NrContractConsumator)
                        $ValabContrDinData1= GUICtrlRead($ValabContrDinData)
                        $ValabContrPanaLaData1= GUICtrlRead($ValabContrPanaLaData)
                        $ValabAnexaDinData1= GUICtrlRead($ValabAnexaDinData)
                        $ValabAnexaPanaLaData1= GUICtrlRead($ValabAnexaPanaLaData)
                        
                    ;If $NumeConsumator<>"" And $CentruConsumator<>"" And $ZonaLicConsumator<>"" And $NrContractTEO<>"" And $NrContractConsumator<>"" And $ValabContrDinData<>"" And $ValabContrPanaLaData<>"" And $ValabAnexaDinData<>"" And $ValabAnexaPanaLaData Then
                        _SQLite_Startup();@ScriptDir&"\SQLite3.dll"
                        $db = _SQLite_Open(@ScriptDir&"consumatoriBD");@ScriptDir&"\ConsumatoriBD.;IF NOT EXISTS
                        _SQLite_Exec($db,"CREATE TABLE IF NOT EXISTS Consumatori(Consumator,Centru,Zona_Licenta,Contract_TEO,Contract_Consumator,ValContract_din,ValContract_pana

,ValAnexa_din,ValAnexa_pana);")
                    ;_SQLite_Exec($db,"insert into table Consumatori values ('"&$NumeConsumator1&"','"&$CentruConsumator1&"','"&$ZonaLicConsumator1&"','"&$NrContractTEO1&"','"&$NrContractConsumator1&"','"&$ValabContrDinData1&"','"&$ValabContrPanaLaData1&"','"&$ValabAnexaDinData1&"','"&$ValabAnexaPanaLaData1&"');")
                        _SQLite_Exec($db,"insert into table Consumatori(Consumator,Centru,Zona_Licenta,Contract_TEO,Contract_Consumator,ValContract_din,ValContract_pana

,ValAnexa_din,ValAnexa_pana) values('"&$NumeConsumator1&"', '"&$CentruConsumator1&"', '"&$ZonaLicConsumator1&"', '"&$NrContractTEO1&"', '"&$NrContractConsumator1&"', '"&$ValabContrDinData1&"', '"&$ValabContrPanaLaData1&"', '"&$ValabAnexaDinData1&"', '"&$ValabAnexaPanaLaData1&"');")
                        _SQLite_GetTable2d($db,"Select * From Consumatori", $aResult, $iRows, $iColumns)
                    ;MsgBox(0,"",_SQLite_Display2DResult($aResult,0,true))
                        _SQLite_Display2DResult($aResult,0,False)
                        _SQLite_Close($db)
                        _SQLite_Shutdown ()
                ;Else
                        MsgBox(0,"Atentie","Nu toate campurile sunt completate!")
                    ;EndIf

                EndSwitch
            WEnd

I do not like stupid and idiot people that write idiot things...If you are one, do not write.

Share this post


Link to post
Share on other sites



Here you go m8 this work ok now

#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <File.au3>

Local $aResult, $iRows, $iColumns
Dim $database = @ScriptDir & "\consumatoriBD.db3"; location of database

If FileExists($database) = 0 Then; Checks for database file if dont exists creates it
    _FileCreate($database)
EndIf

$Form = GUICreate("Prognoza Initiala/Preluare Date/Analiza Contractuala", 653, 447, 411, 216, -1)
$NumeConsumator = GUICtrlCreateInput("", 24, 32, 313, 25)

$Label1 = GUICtrlCreateLabel("Numele Consumatorului", 24, 8, 115, 17)

$DetaliiConsumator = GUICtrlCreateGroup("Detalii despre consumator", 8, 64, 625, 350)
$CentruConsumator = GUICtrlCreateInput("", 28, 118, 273, 21)
$ZonaLicConsumator = GUICtrlCreateInput("", 28, 174, 273, 21)
$NrContractTEO = GUICtrlCreateInput("", 340, 118, 273, 21)
$Label4 = GUICtrlCreateLabel("Numar contract TEO", 340, 94, 102, 17)
$NrContractConsumator = GUICtrlCreateInput("", 340, 174, 273, 21)
$Label5 = GUICtrlCreateLabel("Numar contract Consumator", 340, 150, 136, 17)
$ValabContrDinData = GUICtrlCreateInput("", 148, 246, 153, 21)
$Label6 = GUICtrlCreateLabel("Valabilitate Contract", 260, 206, 98, 17)
$Label2 = GUICtrlCreateLabel("Centrul de care apartine consumatorul", 28, 94, 183, 17)
$Label7 = GUICtrlCreateLabel("Zona de licenta de care apartine consumatorul", 28, 150, 224, 17)
$ValabContrPanaLaData = GUICtrlCreateInput("", 339, 248, 153, 21)
$Label3 = GUICtrlCreateLabel("De la data:", 148, 224, 56, 17)
$Label8 = GUICtrlCreateLabel("Pana la data:", 339, 224, 67, 17)
$Label9 = GUICtrlCreateLabel("Valabilitate Anexa 2 din contract", 240, 296, 200, 17)
$Labe20 = GUICtrlCreateLabel("De la data:", 148, 314, 56, 17)
$ValabAnexaDinData = GUICtrlCreateInput("", 148, 340, 153, 21);a doua
$Labe21 = GUICtrlCreateLabel("Pana la data:", 339, 314, 67, 17)
$ValabAnexaPanaLaData = GUICtrlCreateInput("", 339, 340, 153, 21);a doua
$AdaugaCons = GUICtrlCreateButton(" Adauga consumator", 250, 380, 153, 30)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Select 
        Case $nMsg = $GUI_EVENT_CLOSE
            GUIDelete($Form)
            ExitLoop
        Case $nMsg = $AdaugaCons
            $NumeConsumator1 = GUICtrlRead($NumeConsumator)
            $CentruConsumator1 = GUICtrlRead($CentruConsumator)
            $ZonaLicConsumator1 = GUICtrlRead($ZonaLicConsumator)
            $NrContractTEO1 = GUICtrlRead($NrContractTEO)
            $NrContractConsumator1 = GUICtrlRead($NrContractConsumator)
            $ValabContrDinData1 = GUICtrlRead($ValabContrDinData)
            $ValabContrPanaLaData1 = GUICtrlRead($ValabContrPanaLaData)
            $ValabAnexaDinData1 = GUICtrlRead($ValabAnexaDinData)
            $ValabAnexaPanaLaData1 = GUICtrlRead($ValabAnexaPanaLaData)

        ;If $NumeConsumator<>"" And $CentruConsumator<>"" And $ZonaLicConsumator<>"" And $NrContractTEO<>"" And $NrContractConsumator<>"" And $ValabContrDinData<>"" And $ValabContrPanaLaData<>"" And $ValabAnexaDinData<>"" And $ValabAnexaPanaLaData Then
            _SQLite_Startup();@ScriptDir&"\SQLite3.dll"
            $db = _SQLite_Open($database)
            _SQLite_Exec(-1, "CREATE TABLE IF NOT EXISTS Consumatori(Consumator BLOB, Centru,Zona_Licenta BLOB, Contract_TEO BLOB, Contract_Consumator BLOB, ValContract_din BLOB, ValContract_pana BLOB, ValAnexa_din BLOB, ValAnexa_pana BLOB);")
            
        ;_SQLite_Exec($db,"insert into table Consumatori values ('"&$NumeConsumator1&"','"&$CentruConsumator1&"','"&$ZonaLicConsumator1&"','"&$NrContractTEO1&"','"&$NrContractConsumator1&"','"&$ValabContrDinData1&"','"&$ValabContrPanaLaData1&"','"&$ValabAnexaDinData1&"','"&$ValabAnexaPanaLaData1&"');")
            _SQLite_Exec(-1, 'insert into Consumatori Values("'& $NumeConsumator1 & '","' & $CentruConsumator1 & '","' & $ZonaLicConsumator1 & '","' & $NrContractTEO1 & '","' & $NrContractConsumator1 & '","' & $ValabContrDinData1 & '","' & $ValabContrPanaLaData1 & '","' & $ValabAnexaDinData1 & '","' & $ValabAnexaPanaLaData1 & '"' & ");")
            
            
            _SQLite_GetTable2d($database, "Select * From Consumatori", $aResult, $iRows, $iColumns)
        ;MsgBox(0,"",_SQLite_Display2DResult($aResult,0,true))
            _SQLite_Display2DResult($aResult, 0, False)
            _SQLite_Close($database)
            _SQLite_Shutdown()
        ;Else
            MsgBox(0, "Atentie", "Nu toate campurile sunt completate!")
        ;EndIf

    EndSelect
WEnd

Share this post


Link to post
Share on other sites

Thank you! muttley


I do not like stupid and idiot people that write idiot things...If you are one, do not write.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

hi, good code. Now, is it possible to add some functions? such as, add, delete, sort, browse, etc.

Edited by netegg

Share this post


Link to post
Share on other sites

hi, good code. Now, is it possible to add some functions? such as, add, delete, sort, browse, etc.

Yes. Please post your code once you've done it...

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
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
Sign in to follow this  
Followers 0