Jump to content

Recommended Posts

Posted

@Smoke

First of all thanks for your trick...i've switched the _SQLite_GetTable2d to _SQLite_FetchData now my code is that :

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <GuiListView.au3>
#include <ComboConstants.au3>


$Form1 = GUICreate("Try", 627, 464, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 8, 8, 121, 21)
$Search = GUICtrlCreateButton("Search", 136, 8, 75, 25)
$ListView = GUICtrlCreateListView("Name|Streaming|WebSite|Genre|Country", 0, 40, 626, 382)
Local $hListView = GUICtrlGetHandle($ListView)

GUISetState(@SW_SHOW)

_SQLite_Startup()
_SQLite_Open(@ScriptDir & "\Database.db")

If @error > 0 Then
    MsgBox(16, "SQLite Error", "SQLite.dll Can't be Loaded!")
    Exit
EndIf


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Search
            $Valor = GUICtrlRead ($Input1)
            _Search($Valor)
    EndSwitch
WEnd


Func _Search ($Value) ;Changed, thanks to SmOke_N
_GUICtrlListView_BeginUpdate($ListView)
_GUICtrlListView_DeleteAllItems($ListView)
Local $hQuery, $aRow, $aNames
_SQLite_Query (-1, "SELECT * FROM America WHERE Name LIKE '%" & $Value & "%' UNION SELECT * FROM Europe WHERE Name LIKE '%" & $Value & "%';", $hQuery)
While _SQLite_FetchData($hQuery, $aRow, False , False) = $SQLITE_OK
$Line = $aRow[0] & "|" & $aRow[1] & "|" & $aRow[2] & "|" & $aRow[3] & "|" & $aRow[4]
GuiCtrlCreateListViewItem($Line,$ListView)
WEnd
_SQLite_QueryFinalize($hQuery)
_GUICtrlListView_EndUpdate($ListView)
EndFunc

I've only 5 tables...i thinks is the best way to divided the resarch of radio by Continent...If i do that with only one table, as suggested by Kylomas, i've too much redundant data, with slowest search and bigger database dimension.

Anyone have an idea how to improve this db, and do the search without too much UNION, for a cleanest and faster search?

Hi!

  • Moderators
Posted

Guess you missed my point of being creative with AutoIt.

Example only:

Global $gs_query = _my_UnionTable_NameQueryAllData("radio", "Name", "America", "Europe", "Asia", "Whatever") 
ConsoleWrite($gs_query & @CRLF)

Func _my_UnionTable_NameQueryAllData($s_value, $s_colwhere, $s_table1, $s_table2 = "", $s_table3 = "", $s_table4 = "", $s_table5 = "")
    #forceref $s_table1, $s_table2, $s_table3, $s_table4, $s_table5

    Local $i_params = @NumParams

    Local $s_query = "SELECT * FROM " & $s_table1
    $s_query &= " WHERE " & $s_colwhere & " LIKE '%" & $s_value & "%'"

    If $i_params = 3 Then
        $s_query = "begin;" & $s_query & ";commit;"
        Return $s_query
    EndIf

    For $i = 4 To @NumParams
        $s_query &= " UNION SELECT * FROM " & Eval("s_table" & $i - 2)
        $s_query &= " WHERE " & $s_colwhere & " LIKE '" & $s_value & "'"
    Next

    $s_query = "begin;" & $s_query & ";commit;"

    Return $s_query
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted

@SmOke_N

I don't have understand nothing of your code =P

Why i have to do this autoit function?

Global $gs_query = _my_UnionTable_NameQueryAllData("radio", "Name", "America", "Europe", "Asia", "Whatever")

"Radio" is the string that i've to search?

What do that?

$s_query = "begin;" & $s_query & ";commit;"

What do "begin;" and ";commit;" command?

Your fucntion is not the same of that?

_SQLite_Query (-1, "SELECT * FROM America WHERE Name LIKE '%" & $Value & "%' UNION SELECT * FROM Europe WHERE Name LIKE '%" & $Value & "%';", $hQuery)

Thanks for your help :) and sorry for my too much question =P

  • Moderators
Posted

You said you didn't want to create long strings.

The function creates them for you.

If you want the data from all the tables you want to query, then you do what you need to.

Example Only:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <GuiListView.au3>
#include <ComboConstants.au3>


$Form1 = GUICreate("Try", 627, 464, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 8, 8, 121, 21)
$Search = GUICtrlCreateButton("Search", 136, 8, 75, 25)
$ListView = GUICtrlCreateListView("Name|Streaming|WebSite|Genre|Country", 0, 40, 626, 382)
Local $hListView = GUICtrlGetHandle($ListView)

GUISetState(@SW_SHOW)

_SQLite_Startup()
_SQLite_Open(@ScriptDir & "\Database.db")

If @error > 0 Then
    MsgBox(16, "SQLite Error", "SQLite.dll Can't be Loaded!")
    Exit
EndIf


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Search
            $Valor = GUICtrlRead ($Input1)
            _Search($Valor)
    EndSwitch
WEnd


Func _Search ($Value) ;Changed, thanks to SmOke_N
    _GUICtrlListView_BeginUpdate($ListView)
    _GUICtrlListView_DeleteAllItems($ListView)
    
    Local $hQuery, $aRow, $aNames
    Local $s_query_string = _my_UnionTable_NameQueryAllData($Value, "Name", "America", "Europe"); there are 3 more parameters you can use for the other 3 tables
    _SQLite_Query (-1, $s_query_string, $hQuery)
    While _SQLite_FetchData($hQuery, $aRow, False , False) = $SQLITE_OK
        $Line = $aRow[0] & "|" & $aRow[1] & "|" & $aRow[2] & "|" & $aRow[3] & "|" & $aRow[4]
        GuiCtrlCreateListViewItem($Line,$ListView)
    WEnd
    
    _SQLite_QueryFinalize($hQuery)
    _GUICtrlListView_EndUpdate($ListView)
EndFunc

Func _my_UnionTable_NameQueryAllData($s_value, $s_colwhere, $s_table1, $s_table2 = "", $s_table3 = "", $s_table4 = "", $s_table5 = "")
    #forceref $s_table1, $s_table2, $s_table3, $s_table4, $s_table5

    Local $i_params = @NumParams

    Local $s_query = "SELECT * FROM " & $s_table1
    $s_query &= " WHERE " & $s_colwhere & " LIKE '%" & $s_value & "%'"

    If $i_params = 3 Then
        $s_query = "begin;" & $s_query & ";commit;"
        Return $s_query
    EndIf

    For $i = 4 To @NumParams
        $s_query &= " UNION SELECT * FROM " & Eval("s_table" & $i - 2)
        $s_query &= " WHERE " & $s_colwhere & " LIKE '" & $s_value & "'"
    Next

    $s_query = "begin;" & $s_query & ";commit;"

    Return $s_query
EndFunc

As far as "BEGIN;" AND "COMMIT;", you can google those with sqlite.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted (edited)

Hi,

just 2 cents from me again.

I would prefer creating two tables.

So, you got

Name|Streaming|WebSite|Genre|Country-ID

and a table Country

ID|Name

Mega

Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Posted

Just to add to what has been just posted, I even started some time ago a small model for the OP where I created separate tables for continents, countries, states and radios, all using foreign keys to link them up.

To StungStang, you really should google for an SQL primer and build from there. BTW did you get my PM? If so, what do you think?

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)

Posted

The really problem is how to set the database?

A structure like that :

1 Table for 5 Continent:

Table America
-->Name|Streaming|Web Site|Genre|Country

Or 1 Table for all entry

Table All Station
-->Name|Streaming|Web Site|Genre|Continent|Country

Or 2 Table, one for station data and 1 for ID Continent

Table Radio
-->Name|Streaming|Web Site|Genre|Country|ID continent

Table Continent
-->Continent|ID

Or what else?....

@jchd

I see your dll, but i thinks is unnecessary for my script (or not?)...It will be good for other progett :)

Thanks!

Posted

Hi,

I would do something like this:

DROP TABLE IF EXISTS "Country";
CREATE TABLE "Country" (
 "ID" NUMERIC PRIMARY KEY  NOT NULL, 
 "Name" VARCHAR
);
INSERT INTO "Country" VALUES(1,'USA');
INSERT INTO "Country" VALUES(2,'Germany');
INSERT INTO "Country" VALUES(3,'Italy');
INSERT INTO "Country" VALUES(4,'England');
DROP TABLE IF EXISTS "Radio";
CREATE TABLE "Radio" (
 "ID"  PRIMARY KEY  NOT NULL, 
 "Name" VARCHAR,
 "Streaming" VARCHAR,
 "Site" VARCHAR,
 "Genre" VARCHAR,
 "State" VARCHAR,
 "Country-ID" NUMERIC,
 FOREIGN KEY("Country-ID") REFERENCES "Country"("ID")
);
INSERT INTO "Radio" VALUES('MyRadio','mms://myradio.asx','www.myradio.com','Rock','California','1',1);
INSERT INTO "Radio" VALUES('MyPreRadio','mms://myrad2io.asx','www.myprefradio.com','Pop','Florida','2',2);
INSERT INTO "Radio" VALUES('MyExamle','mms://link.mp3','www.myexample.com','Dance','New York','3',3);
INSERT INTO "Radio" VALUES('MyExamle2','mms://link.mp32','www.myexample2.com','Trance','Chicago','2',4);

You can save this as bla.sql and import it with SQLite Manager (add-on) for firefox.

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Posted (edited)

The general idea with DB design is to normalize the tables so that it minimizes the redundancy of information. It's not only a question of used space, but merely a question of integrity. Selecting a country within a continent is easier to get right than typing/validating the name of a continent and a country spelling. Same for states and other data. Furthermore, this allows a much more efficient indexing (also using much less space both on diskk and memory).

Using the foreign key mecanism further enhances integrity as it's now impossible to make bad mistakes, i.e. add a state in a non-existent country or register a radio in non-existent genre, a.s.o..

Even if all this seems a bit too much complex for a simple DB like yours, it's a good design practice and will give you a strong basis should your application become more complex over time, or should you have a more complex project next.

Edited by jchd

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)

Posted

You do a table for All radio station, another for the id of continent :)

It the same to that :

Table All Station
-->Name|Streaming|Web Site|Genre|Continent|Country

Where i can assign a number for continet, for example 1= America, 2= Europe, ecc...

I waithing for other soluction ,to compare other ideas :)

Hi!

Posted

Sorry, I do not get you.

Any question left? Did you see my SQl to create your DB structure?

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Posted

If i do your metod...with 2 table, one only for id...

In my script how i can convert the number "1" to USA, etc...?

For you this is the better way? =)

Sorry, but this database confusing me too much @_@

Hi!

  • Moderators
Posted

You need a good db manager tool, some of us use SQLite Expert here, here are some more:

http://www.sqlite.org/cvstrac/wiki?p=ManagementTools

You also need to learn how to use SQLite:

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

You might want to look specifically at functions you can use.

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

Keep in mind, though we have a "User Defined Function" base for SQLite, it's not AutoIt, it's something we can access/manipulate/utilize in AutoIt.

For specific questions like you have that are based on DB structure and DB access, you should consort with a SQLite forum. Not only would your questions be answered faster more than likely, but you'd be asking the your questions in the right place.

SQLite Forum ( First I came too ):

http://sqliteforum.com/

SQLite IRC:

#sqlite freenode

Good luck.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted (edited)

Hi,

first of all, do what SmOke_N said. :)

Read a little bit about sqlite.

Back to your question.

If you have the db structure like it showed above, then it is still no problem to get your infos even with column CountryID by Name.

SELECT r.*, c.Name
FROM Radio  r, Country c
WHERE r.CountryID = c.ID
AND r.Name like '%l%';

I can sent you the database if you want.

Mega

Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Posted

A (last ?) word before you leave this forum for another with this topic...

If you really want to add "continent" information, then add this in the Country table instead of the Radio table (makes more sense, and less redundancy). You may even make a specific table for that, but that's not really a great idea as I suspect you won't have thousands of countries.

And for the 'genre' field, you should also better makea third table for this, constructed and linked with Radio table the same way as suggested by Xenobiologist for "Country" table,

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
  • Recently Browsing   0 members

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