rony2006 Posted August 25, 2013 Share Posted August 25, 2013 Hello, I am beginner in Autoit and i want to create, read, edit and delete a simple database. For exemple I have the default database: 1 Tom 1000 2 Bill 1200 3 Marian 2000 And i have $variabile1 = 200 $variabile2 = 300 $variabile3 =250 Next, i want to add the value of variabile1 to 1000 and then the database to look something like: 1 Tom 1200 2 Bill 1200 3 Marian 2000 And last thing i want to $var1 to have the new values of row 1 for ex $var1 = 1 Tom 1200 How can i do this in the most simple way? Can you give me some exemple? If is posibile i want to use a .txt file for the database, but i think do it also with sqlite but i dont know how to do it. Thank you! Link to comment Share on other sites More sharing options...
Danyfirex Posted August 25, 2013 Share Posted August 25, 2013 Look into help file. expandcollapse popup#include <SQLite.au3> #include <SQLite.dll.au3> Local $aResult, $iRows, $iColumns, $iRval _SQLite_Startup() If @error Then MsgBox(16, "SQLite Error", "SQLite.dll Can't be Loaded!") Exit -1 EndIf ConsoleWrite("_SQLite_LibVersion=" & _SQLite_LibVersion() & @CRLF) _SQLite_Open() ; Open a :memory: database If @error Then MsgBox(16, "SQLite Error", "Can't Load Database!") Exit -1 EndIf ;Example Table ; ID | Name | Age ; ----------------------- ; 1 Alice | 43 ; 2 Bob | 28 ; 3 Cindy | 21 If Not _SQLite_Exec(-1, "CREATE TEMP TABLE persons (ID,Name, Age);") = $SQLITE_OK Then _ MsgBox(16, "SQLite Error", _SQLite_ErrMsg()) If Not _SQLite_Exec(-1, "INSERT INTO persons VALUES (1,'Alice','43');") = $SQLITE_OK Then _ MsgBox(16, "SQLite Error", _SQLite_ErrMsg()) If Not _SQLite_Exec(-1, "INSERT INTO persons VALUES (2,'Bob','28');") = $SQLITE_OK Then _ MsgBox(16, "SQLite Error", _SQLite_ErrMsg()) If Not _SQLite_Exec(-1, "INSERT INTO persons VALUES (3,'Cindy','21');") = $SQLITE_OK Then _ MsgBox(16, "SQLite Error", _SQLite_ErrMsg()) ; Query $iRval = _SQLite_GetTable2d(-1, "SELECT * FROM persons;", $aResult, $iRows, $iColumns) If $iRval = $SQLITE_OK Then _SQLite_Display2DResult($aResult) ;~ $aResult looks like this: ;~ ;~ ID Name Age ;~ 1 Alice 43 ;~ 2 Bob 28 ;~ 3 Cindy 21 ;~ ;~ If the dimensions would be switched in _SQLite_GetTable2d the result would look like this: ;~ ;~ Name Alice Bob Cindy ;~ Age 43 28 21 Else MsgBox(16, "SQLite Error: " & $iRval, _SQLite_ErrMsg()) EndIf _SQLite_Close() _SQLite_Shutdown() regards Zohar and Gianni 2 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
rony2006 Posted August 25, 2013 Author Share Posted August 25, 2013 Thanks, but if i run that code, were is the database created? I want for ex to make the database in c:/database.db and work on it. Link to comment Share on other sites More sharing options...
Danyfirex Posted August 25, 2013 Share Posted August 25, 2013 Look _SQLite_Open in the example code. expandcollapse popup#include <SQLite.au3> #include <SQLite.dll.au3> Local $aResult, $iRows, $iColumns, $iRval _SQLite_Startup() If @error Then MsgBox(16, "SQLite Error", "SQLite.dll Can't be Loaded!") Exit -1 EndIf ConsoleWrite("_SQLite_LibVersion=" & _SQLite_LibVersion() & @CRLF) _SQLite_Open() ; Open a :memory: database If @error Then MsgBox(16, "SQLite Error", "Can't Load Database!") Exit -1 EndIf Local $hDskDb = _SQLite_Open(@ScriptDir & '\my.db') ;this is the path ; Open a permanent disk database If @error Then MsgBox(16, "SQLite Error", "Can't open or create a permanent Database!") Exit -1 EndIf ;Example Table ; ID | Name | Age ; ----------------------- ; 1 Alice | 43 ; 2 Bob | 28 ; 3 Cindy | 21 ;~ If Not _SQLite_Exec(-1, "CREATE TABLE persons (ID,Name, Age);") = $SQLITE_OK Then _ ;~ MsgBox(16, "SQLite Error", _SQLite_ErrMsg()) ;~ If Not _SQLite_Exec(-1, "INSERT INTO persons VALUES (1,'Alice','43');") = $SQLITE_OK Then _ ;~ MsgBox(16, "SQLite Error", _SQLite_ErrMsg()) ;~ If Not _SQLite_Exec(-1, "INSERT INTO persons VALUES (2,'Bob','28');") = $SQLITE_OK Then _ ;~ MsgBox(16, "SQLite Error", _SQLite_ErrMsg()) ;~ If Not _SQLite_Exec(-1, "INSERT INTO persons VALUES (3,'Cindy','21');") = $SQLITE_OK Then _ ;~ MsgBox(16, "SQLite Error", _SQLite_ErrMsg()) ; Query $iRval = _SQLite_GetTable2d(-1, "SELECT * FROM persons;", $aResult, $iRows, $iColumns) If $iRval = $SQLITE_OK Then _SQLite_Display2DResult($aResult) ;~ $aResult looks like this: ;~ ;~ ID Name Age ;~ 1 Alice 43 ;~ 2 Bob 28 ;~ 3 Cindy 21 ;~ ;~ If the dimensions would be switched in _SQLite_GetTable2d the result would look like this: ;~ ;~ Name Alice Bob Cindy ;~ Age 43 28 21 Else MsgBox(16, "SQLite Error: " & $iRval, _SQLite_ErrMsg()) EndIf _SQLite_Close() _SQLite_Shutdown() saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
TheSaint Posted August 25, 2013 Share Posted August 25, 2013 If you want the simplest of ways, then check out IniWrite and the other ini commands. Some will tell you that INI files are redundant, but I've seen very little evidence of that ... and they've been saying that for years. They have their benefits ... especially manual edits with Notepad, size and portability. mLipok, Danyfirex and JCEF 3 Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now