# Filtering the tableView with args from SQL

**URL:** <https://forums.solar2d.com/t/filtering-the-tableview-with-args-from-sql/336333>\
**Category:** Widgets\
**Created:** [October 18, 2015, 6:46pm UTC](https://forums.solar2d.com/t/filtering-the-tableview-with-args-from-sql/336333 "2015-10-18T18:46:54Z")\
**Posts on this page:** 11\
**Page:** 3

<div class="post-metadata">

**Author:** ![Hendrix000007](https://forums.solar2d.com/user_avatar/forums.solar2d.com/hendrix000007/32/1396_2.png) [@Hendrix000007](https://forums.solar2d.com/u/Hendrix000007)\
**Post date:** [November 2, 2015, 11:30am UTC](https://forums.solar2d.com/t/filtering-the-tableview-with-args-from-sql/336333/41 "2015-11-02T11:30:09Z")

</div>

Heres the link: www.ferrobet.no/NatureApp.zip

I have adjusted the content so it matches the db file 🙂

The way I made it is like the class:&nbsp;ButtonsBirds.lua -(inside the Classes folder), inserts the button args into the table mySqlView trough the function&nbsp;engineResponse() --this can be like if I press the Red bodycolour button it will send&nbsp;“BODYCOLOUR = ‘Red’” or in your way: table.insert(birdAttributesQuery, unpack({ key = “ART”, value = “Andefamilien”, condition = “AND” })) , right?

OK, I will be extremely glad if you can help with this “little thing” that stops my whole project Rob 🙂

Thanx for all help

---

<div class="post-metadata">

**Author:** ![Hendrix000007](https://forums.solar2d.com/user_avatar/forums.solar2d.com/hendrix000007/32/1396_2.png) [@Hendrix000007](https://forums.solar2d.com/u/Hendrix000007)\
**Post date:** [November 3, 2015, 1:25pm UTC](https://forums.solar2d.com/t/filtering-the-tableview-with-args-from-sql/336333/42 "2015-11-03T13:25:48Z")

</div>

Rob

Did you find anything?

---

<div class="post-metadata">

**Author:** ![rob](https://forums.solar2d.com/user_avatar/forums.solar2d.com/rob/32/4_2.png) [@rob](https://forums.solar2d.com/u/rob)\
**Post date:** [November 4, 2015, 1:24am UTC](https://forums.solar2d.com/t/filtering-the-tableview-with-args-from-sql/336333/43 "2015-11-04T01:24:00Z")

</div>

I’ve not gotten to it yet. With any luck I can look at it tonight.

Rob

---

<div class="post-metadata">

**Author:** ![rob](https://forums.solar2d.com/user_avatar/forums.solar2d.com/rob/32/4_2.png) [@rob](https://forums.solar2d.com/u/rob)\
**Post date:** [November 4, 2015, 4:10am UTC](https://forums.solar2d.com/t/filtering-the-tableview-with-args-from-sql/336333/44 "2015-11-04T04:10:47Z")

</div>

Your app comes up with a black screen and no errors in the console.&nbsp; Can I get working project?

Rob

---

<div class="post-metadata">

**Author:** ![Hendrix000007](https://forums.solar2d.com/user_avatar/forums.solar2d.com/hendrix000007/32/1396_2.png) [@Hendrix000007](https://forums.solar2d.com/u/Hendrix000007)\
**Post date:** [November 4, 2015, 10:50am UTC](https://forums.solar2d.com/t/filtering-the-tableview-with-args-from-sql/336333/45 "2015-11-04T10:50:28Z")

</div>

Ahh, sorry Rob I uploaded a wrong version

Heres the link: www.ferrobet.no/NatureApp.zip

This is not with your piece of code because the function functionSqlView() produces the right statements when you click one of the buttons at the bottom. I have been reading one of your replies in another forum post where you discuss where to put the different components of the tableView structure when dealing with composer and going back and forth through composer pages/scenes.

So I rearranged my code and took the onRowrender function from will show over to create scene then it started to re-render my rows again 🙂

Anyway, I think my real q here is: how do I sort and show the data I now have to the display?

I think the problem lies at **line 61** in playGame file

When this is sorted out, I will use your approach on the functionSqlView function

…I liked it ;D

---

<div class="post-metadata">

**Author:** ![rob](https://forums.solar2d.com/user_avatar/forums.solar2d.com/rob/32/4_2.png) [@rob](https://forums.solar2d.com/u/rob)\
**Post date:** [November 5, 2015, 3:20am UTC](https://forums.solar2d.com/t/filtering-the-tableview-with-args-from-sql/336333/46 "2015-11-05T03:20:39Z")

</div>

Where does your database exist? I didn’t see it in system.DocumentsDirectory. I don’t see where you’re creating/populating it.

Rob

---

<div class="post-metadata">

**Author:** ![Hendrix000007](https://forums.solar2d.com/user_avatar/forums.solar2d.com/hendrix000007/32/1396_2.png) [@Hendrix000007](https://forums.solar2d.com/u/Hendrix000007)\
**Post date:** [November 5, 2015, 6:23am UTC](https://forums.solar2d.com/t/filtering-the-tableview-with-args-from-sql/336333/47 "2015-11-05T06:23:03Z")

</div>

You are right, when I check the proj sandbox and it´s nothing there? but it fires up the db that lies in the root dir: ‘Birds.sqlite’ in line 250 (where I iterate over the sql statement), in playGame if I´m not mistaken

but I´m not shure

If you like to se how I like it to be you can first run the code in sim and see (you see all entries), then you can put i.e. this statement in line 245 right before count = 0:&nbsp;

[LUA]“SELECT \* FROM birds WHERE COLOR1 = ‘Sort’”[/LUA]

and save. what you now see in the simulator is a narrow selection just like I want right?

---

<div class="post-metadata">

**Author:** ![Hendrix000007](https://forums.solar2d.com/user_avatar/forums.solar2d.com/hendrix000007/32/1396_2.png) [@Hendrix000007](https://forums.solar2d.com/u/Hendrix000007)\
**Post date:** [November 5, 2015, 8:36pm UTC](https://forums.solar2d.com/t/filtering-the-tableview-with-args-from-sql/336333/48 "2015-11-05T20:36:33Z")

</div>

I made a video that describes better my situation:

[https://www.dropbox.com/s/z16sowhc2gtmpfq/BirdAppComposer.mp4?dl=0&nbsp;](https://www.dropbox.com/s/z16sowhc2gtmpfq/BirdAppComposer.mp4?dl=0%C2%A0)

This shows how I want it to work in the update process 🙂

---

<div class="post-metadata">

**Author:** ![rob](https://forums.solar2d.com/user_avatar/forums.solar2d.com/rob/32/4_2.png) [@rob](https://forums.solar2d.com/u/rob)\
**Post date:** [November 7, 2015, 7:21pm UTC](https://forums.solar2d.com/t/filtering-the-tableview-with-args-from-sql/336333/49 "2015-11-07T19:21:26Z")

</div>

There is an issue with the SQL going to the db:nrows() call that’s not returning anything from the query.&nbsp; Still investigating.

---

<div class="post-metadata">

**Author:** ![Hendrix000007](https://forums.solar2d.com/user_avatar/forums.solar2d.com/hendrix000007/32/1396_2.png) [@Hendrix000007](https://forums.solar2d.com/u/Hendrix000007)\
**Post date:** [December 30, 2015, 8:18am UTC](https://forums.solar2d.com/t/filtering-the-tableview-with-args-from-sql/336333/50 "2015-12-30T08:18:07Z")

</div>

I will like to thank you, Rob for all help you have done for me

Everything is working nicely now. Here´s the trick from your code that helped me out 🙂

[LUA]

function functionSqlView()&nbsp;

&nbsp; local sql = nil  
&nbsp; tableView:deleteAllRows()

&nbsp; local counter = 1  
&nbsp; local res&nbsp;&nbsp;&nbsp;&nbsp; = {}

– NOW WE BUILD THE SQL QUERY IN A FORLOOP FROM THE mySqlView TABLE, INSERTED FROM THE SUBBUTTONS VALUES  
&nbsp; sql = "SELECT \* FROM birds WHERE "  
&nbsp; for k, v in ipairs(mySqlView) do  
&nbsp;&nbsp;&nbsp; sql = sql … v … " "  
&nbsp;&nbsp;&nbsp; if counter \< #mySqlView then  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sql = sql … " AND "  
&nbsp;&nbsp;&nbsp; end  
&nbsp;&nbsp;&nbsp; counter = counter + 1  
&nbsp; end

&nbsp; &nbsp; &nbsp; dbTable = {}&nbsp; – START WITH A FRESH TABLE

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; count = 0&nbsp; – AND FRESH COUNTER

– PREPARE THE ROWS SELLECTION BASED ON THE DATABASE ROWS THROUGH THE SQL QUERY  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for row in db:nrows( sql ) do  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; count = count +1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbTable[count]={}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbTable[count].NAME = row.NAME  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbTable[count].LATIN = row.LATIN  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbTable[count].INFO = row.INFO  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end  
– STYLING FOR THE ROWS ON SCREEN  
&nbsp;&nbsp;&nbsp; for i = 1, #dbTable do  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local isCategory = false  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local rowHeight = 95  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local rowColor = {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default = { colorConverter(114, 72, 30, 0) },  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local lineColor = { colorConverter(20, 20, 0, 0) }

– Insert the row into the tableView  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tableView:insertRow  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rowHeight = rowHeight,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rowColor = rowColor,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lineColor = lineColor,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp; end  
&nbsp;&nbsp;&nbsp; return true  
end

[/LUA]

Again, thanx a lot Rob

---

<div class="post-metadata">

**Author:** ![rob](https://forums.solar2d.com/user_avatar/forums.solar2d.com/rob/32/4_2.png) [@rob](https://forums.solar2d.com/u/rob)\
**Post date:** [December 30, 2015, 11:02pm UTC](https://forums.solar2d.com/t/filtering-the-tableview-with-args-from-sql/336333/51 "2015-12-30T23:02:02Z")

</div>

Quite welcome!

[Previous page](https://forums.solar2d.com/t/filtering-the-tableview-with-args-from-sql/336333.md?page=2)
