AutoHotkey Community

It is currently May 27th, 2012, 5:08 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 64 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject:
PostPosted: January 25th, 2010, 9:11 pm 
Is the use of the CSV file necessary? Is it possible to create a DB and build a table without importing from the CSV file?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2010, 9:20 pm 
Nevermind, I just answered my own question. (No, Yes).


Report this post
Top
  
Reply with quote  
 Post subject: ResultsGUI
PostPosted: February 4th, 2010, 6:42 pm 
I created this script for testing SQL Commands & Queries with SQLite.ahk (http://www.autohotkey.com/forum/topic12752.html).

On opening, the only commands it sends to SQLite are to Startup SQLite and to Open the Database.

The first time the CREATE TABLE command is executed, the table created is set as the variable TableName. If you're creating multiple tables, you'll want to create your main table first.

If "SELECT" is present in your Query/Command, then the _SQLite_GetTable function is used, otherwise the _SQLite_Exec function is used, and then the query "SELECT * FROM TableName" is ran, to display your changes.

The ListView's column headers are dynamically added from the column names returned from the SELECT query. This could also be used in non-SQL GUIs to create dynamic ListView column headers, if needed.

Some of this code is modified from searches I've done in the forums, so I'm not claiming to have created this entirely from scratch.

Feel free to modify and redistribute.

Code:
#SingleInstance, Force
#Include, SQLite.ahk

DBFileName = TEST.DB

IfExist, %DBFileName%
{
   SB_SetText("Deleting Current Database")
   FileDelete, %DBFileName%
}

Gui, Add, Text, x6 y7 w100 h20 , Query/Command:
Gui, Add, Edit, x106 y7 w590 h20 vSQL,
Gui, Add, Button, x706 y7 w80 h20 gRunQC, Run
Gui, Add, GroupBox, x6 y37 w780 h330 , Results
Gui, Add, ListView, x16 y57 w760 h300 vResultsLV,
Gui, Add, StatusBar,,
Gui, Show, h389 w795, SQL Query/Command ListView Function GUI
GoSub, StartupOpen
Return

GuiClose:
RC := _SQLite_CloseDB($SQLITE_h_DB)
If (RC <> 0)
   MsgBox, Error Closing Database: %RC%`n$SQLITE_s_ERROR
RC := _SQLite_Shutdown()
ExitApp

StartupOpen:
RC := _SQLite_Startup()
If (RC <> 0)
   SB_SetText("Error Starting SQLite: " . RC)
Else
   SB_SetText("SQLite Startup")

RC := _SQLite_OpenDB(DBFileName)
If (RC <> 0)
   SB_SetText("Error Opening Database: " . RC)
Else
   SB_SetText("Database Opened")
Return

RunQC:
GuiControlGet, SQL

If SQL is space
{
   SB_SetText("No Text Entered")
   Return
}

SQL := SQL . ";"

If TableName is space
{
   IfInString, SQL, CREATE TABLE
   {
      StringSplit, TableName, SQL, %A_Space%
      TableName := TableName3
   }
}

IfInString, SQL, SELECT
   SQLType := "Query"
Else
   SQLType := "Command"

If SQLType = Query
{
   SB_SetText("Running Query: " . SQL)
   RC := _SQLite_GetTable(-1, SQL, Result, $iRows, $iCols)
   If (RC <> 0)
      SB_SetText("Error GETTABLE: " . $SQLITE_h_DB . " " . RC . " " . $SQLITE_s_ERROR)

   Gui, Listview, ResultsLV

   LV_Delete()

   ColumnCount := LV_GetCount("Column")
   Loop, %ColumnCount%
   {
      LV_DeleteCol(1)
   }

   Loop, Parse, Result, `n
   {
      If (A_Index = 1)
      {
         Loop, Parse, A_LoopField, |
            LV_InsertCol(A_Index,"",A_LoopField)
      }
      Else
      {
         row := LV_Add("", "")
         Loop, Parse, A_LoopField, |
         {
            LV_Modify(row, "Col" . A_Index, A_LoopField)
            LV_ModifyCol(A_Index, "AutoHdr")
         }
      }
   }
   SB_SetText("")
}
Else
{
   SB_SetText("Executing Command: " . SQL)
   RC := _SQLite_Exec(-1, SQL)
   If (RC <> 0)
   {
      SB_SetText("Error EXEC: " . RC . " | " . $SQLITE_s_ERROR)
   }

   SQL := "SELECT * FROM " . TableName . ";"

   RC := _SQLite_GetTable(-1, SQL, Result, $iRows, $iCols)
   If (RC <> 0)
      SB_SetText("Error GETTABLE: " . $SQLITE_h_DB . " " . RC . " | " . $SQLITE_s_ERROR)

   Gui, Listview, ResultsLV

   LV_Delete()

   ColumnCount := LV_GetCount("Column")
   Loop, %ColumnCount%
   {
      LV_DeleteCol(1)
   }

   Loop, Parse, Result, `n
   {
      If (A_Index = 1)
      {
         Loop, Parse, A_LoopField, |
            LV_InsertCol(A_Index,"",A_LoopField)
      }
      Else
      {
         row := LV_Add("", "")
         Loop, Parse, A_LoopField, |
         {
            LV_Modify(row, "Col" . A_Index, A_LoopField)
            LV_ModifyCol(A_Index, "AutoHdr")
         }
      }
   }
   SB_SetText("")
}
Return


Here is a small list of commands/queries to run (in order) to test it's functionality:

Code:
CREATE TABLE Test (ID, Name, Age)
INSERT INTO Test VALUES(1, 'Bob', 28)
INSERT INTO Test VALUES(2, 'Anna', 26)
INSERT INTO Test VALUES(3, 'George', 19)
SELECT * FROM Test WHERE Age>21


Report this post
Top
  
Reply with quote  
PostPosted: May 11th, 2010, 2:54 am 
Offline

Joined: October 20th, 2007, 10:40 am
Posts: 15
Location: china,hubei
At First, thanks nick to made this great lib

i am useing the latest sqlite3.dll and your sqlite.ahk
I found that, when i insert a 'big' text into the table
and then i query this record, then ahk break down

this is my text code

Code:
#Include SQLite.ahk
F1::
DBpath = aaa.db
bbbb = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

   _SQLite_Startup() , _SQLite_OpenDB(DBPath)

   SQLstr = create table aaa (id integer, dataA text)
   _SQLite_Exec(-1, SQLstr)

   SQLstr = INSERT INTO aaa VALUES (55, '%bbbb%')
   _SQLite_Exec(-1, SQLstr)

   _SQLite_CloseDB(-1) , _SQLite_ShutDown()
return

F2::
   SQLstr = select * from aaa where id=55
   _SQLite_Startup() , _SQLite_OpenDB(DBPath)
   _SQLite_GetTable(-1, SQLstr, tmp13423, RowNum, ColNum)
   _SQLite_CloseDB(-1) , _SQLite_ShutDown()
   msgbox, % tmp13423
return




I cant't find out which couse this result, so can you test and reply ?

thanks again


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 11th, 2010, 4:24 pm 
Offline

Joined: August 24th, 2005, 5:29 pm
Posts: 549
Location: Berlin / Germany
Moin,

_SQLite_GetTable() is calculating the maximum lenght of field values as VarSetCapacity($s_Col, $iCharSize * 4, 0), i.e. 256 by default. You may try to call the function with some higher value in the parameter $iCharSize.

Otherwise you can find a newer version of SQLite.ahk in the German AHK forum. I didn't find the time to translate it yet, but maybe a Google translation will help you to understand. Caution: It isn't tested really hard. :wink:

_________________
nick :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 31st, 2010, 7:32 am 
Hi, I am having trouble with a DELETE.

I am trying this

Code:

$sSQL := "DELETE * FROM TABLE_SAMPLE WHERE COLUMN_TEST = 'HELLO'";



It does not appear to be working. Any clues?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 1st, 2010, 6:19 am 
Code:
$sSQL := "DELETE * FROM TABLE_SAMPLE WHERE COLUMN_TEST = 'HELLO';"
:?:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 3rd, 2010, 4:20 pm 
Offline

Joined: March 26th, 2010, 5:55 pm
Posts: 129
This is great! Thank you!

I was just about to suggest an optional parameter that allows you to change the column or row delimiters, in case the values might contain | or `n, but I see that the newer version from the German forum already has that functionality.

I also like that the newer version appears to be set up to work as a stdlib, and doesn't pollute the global namespace with global variables.

So again, thank you!

Edit: One more thing, when using the new version, make sure #noenv is enabled somewhere in your script, or it may mysteriously fail with access violations in the DLL calls.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 4th, 2010, 7:48 am 
nick (n-l-i) wrote:
Code:
$sSQL := "DELETE * FROM TABLE_SAMPLE WHERE COLUMN_TEST = 'HELLO';"
:?:


Nick thank you for that. I actually re-checked my code line, and I really did have the ; where you did. This did not correct my situation.

But this is what I am parsing, maybe something else is amiss,

:)

Code:

_SQLite_Startup()
_SQLite_OpenDB($sDBFileName)

$sSQL := "DELETE * FROM TABLE_SAMPLE WHERE COLUMN_TEST = 'TEST';"

_SQLiteExec($SQLITE_h_DB, $sSQL)

_SQLite_CloseDB(-1)
_SQLite_ShutDown()



I don't know what is wrong. I seem to be follow syntax for inserting, and reading from the DB... which all works fine. But cannot get the DEL to work, and the parsing seems to be OK. :?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 4th, 2010, 1:45 pm 
Offline
User avatar

Joined: May 10th, 2007, 10:54 am
Posts: 649
Location: .switzerland
Code:
$sSQL := "DELETE FROM TABLE_SAMPLE WHERE COLUMN_TEST = 'TEST';"

without the * ?

http://www.sqlite.org/lang_delete.html

_________________
http://securityvision.ch
AHK 2D GAME ENGINE


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 4th, 2010, 2:19 pm 
Offline

Joined: March 26th, 2010, 5:55 pm
Posts: 129
Check the return values and use _SQLite_ErrMsg to narrow the problem.

From your code fragment I can't tell if the file is invalid or read-only. I can't tell if the table exists.

Besides "not apparently working", what is the symptom?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 5th, 2010, 7:00 am 
Hiyas. This was very frustrating but getting some results.

Thank you kindly gentlemen. I was having trouble creating the error show. working on that

But, the ISNULL version of del, which I tried before -- actually is the correct delete method, and wipes out all matching records meeting the column criteria shown.

But what was confusing b4, is the data in the table, appears to be 'marked' up for deletion, and is not cleared out until the next time a record is inserted. Although this is minor, curious if there is a way to 'clean-house', so when I ask the DB to delete a row or series of rows, it removes the info from the DB immediately :cool:

The way to prove this, is to run a DELETE on a small sample DB. Then drag and drop the DB file into notepad or something. It is slightly cryptic, but you can tell the record you deleted is still hanging in there. Upon any new insertion, it should vanish later.

I can, insert and delete something, and try to read it and it will appear to be done. I guss this is the way SQL Lite handles deletes thank you all


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 7th, 2010, 2:07 pm 
Offline

Joined: July 17th, 2008, 9:46 am
Posts: 225
where Is the Script :D
I want it 8)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 11th, 2010, 10:19 am 
Offline
User avatar

Joined: January 25th, 2006, 8:08 am
Posts: 225
Location: Froschtümpel
I reposted the code and the example in the german forum:

http://de.autohotkey.com/forum/viewtopic.php?t=7350


Report this post
Top
 Profile  
Reply with quote  
PostPosted: November 2nd, 2010, 3:40 am 
Offline

Joined: October 31st, 2010, 3:02 am
Posts: 87
it's great job, and working correctly in ahk. but when i swith to ahk_l unicode version, it doesnot working as before, Could you please make a compatible warper?
BTW: I found a similar wraper in autoit, and try to translate to ahk, but i konw litter about 'dllcall' :oops:
wish someday ahk can support sqlite natively, :P


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 64 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Stigg and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group