# SQLite Select

**URL:** <https://forum.xojo.com/t/sqlite-select/71132>\
**Category:** iOS\
**Created:** [July 12, 2022, 8:54am UTC](https://forum.xojo.com/t/sqlite-select/71132 "2022-07-12T08:54:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_Fitzgibbons](https://forum.xojo.com/user_avatar/forum.xojo.com/martin_fitzgibbons/32/259_2.png) [@Martin\_Fitzgibbons](https://forum.xojo.com/u/Martin_Fitzgibbons)\
**Post date:** [July 12, 2022, 8:54am UTC](https://forum.xojo.com/t/sqlite-select/71132/1 "2022-07-12T08:54:49Z")

</div>

How close did I get? I am having trouble finding an example query to do what I want.

I want to get the name or address from 2 edit fields that match the records that contain the text from those edit fields

```auto
rowsFound = db.SelectSQL("SELECT * FROM Team WHERE Name LIKE ? OR Address LIKE ?",myName , MyAddress)

```

---

<div class="post-metadata">

**Author:** ![Tom\_Dixon](https://forum.xojo.com/user_avatar/forum.xojo.com/tom_dixon/32/605_2.png) [@Tom\_Dixon](https://forum.xojo.com/u/Tom_Dixon)\
**Post date:** [July 12, 2022, 12:56pm UTC](https://forum.xojo.com/t/sqlite-select/71132/2 "2022-07-12T12:56:40Z")

</div>

> [@Martin\_Fitzgibbons](#):
>
> `rowsFound = db.SelectSQL("SELECT * FROM Team WHERE Name LIKE ? OR Address LIKE ?",myName , MyAddress)`

Try

```auto
rowsFound = db.SelectSQL("SELECT * FROM Team WHERE Name LIKE '%" + myName + "%' OR Name LIKE '%" + MyAddress + "%'")

```

This isn’t the only way but it is the way I would do it. Using the % wildcard allows you to match the string as a partial to whatever is in the Name field.

[https://www.sqlitetutorial.net/sqlite-like/](https://www.sqlitetutorial.net/sqlite-like/)

---

<div class="post-metadata">

**Author:** ![Martin\_Fitzgibbons](https://forum.xojo.com/user_avatar/forum.xojo.com/martin_fitzgibbons/32/259_2.png) [@Martin\_Fitzgibbons](https://forum.xojo.com/u/Martin_Fitzgibbons)\
**Post date:** [July 13, 2022, 3:48am UTC](https://forum.xojo.com/t/sqlite-select/71132/3 "2022-07-13T03:48:31Z")

</div>

Thanks Tom, I was close haha I have the hang of the syntax now. What is the difference between MATCH and LIKE? I swapped them but they seem to do the same thing or is there a subtle difference?  
Also thanks for the Tutorial reference it had some better explanations compared to the ones I found.

---

<div class="post-metadata">

**Author:** ![Tom\_Dixon](https://forum.xojo.com/user_avatar/forum.xojo.com/tom_dixon/32/605_2.png) [@Tom\_Dixon](https://forum.xojo.com/u/Tom_Dixon)\
**Post date:** [July 13, 2022, 4:16pm UTC](https://forum.xojo.com/t/sqlite-select/71132/4 "2022-07-13T16:16:27Z")

</div>

I’ve never used MATCH, but I would avoid using MATCH. You may get unexpected results. The documentation I Googled says this:

> The `MATCH` operator is a special syntax for the match() application-defined function. The default match() function implementation raises an exception and is not really useful for anything. But extensions can override the match() function with more helpful logic.

---

<div class="post-metadata">

**Author:** ![Martin\_Fitzgibbons](https://forum.xojo.com/user_avatar/forum.xojo.com/martin_fitzgibbons/32/259_2.png) [@Martin\_Fitzgibbons](https://forum.xojo.com/u/Martin_Fitzgibbons)\
**Post date:** [July 15, 2022, 7:29am UTC](https://forum.xojo.com/t/sqlite-select/71132/5 "2022-07-15T07:29:10Z")

</div>

Hi Tom,  
I have 3 text fields that I am reading and writing to ok but want to add a couple of pictures in 2 extra fields. I have been playing for a few days but can’t get it right (IOS)  
Do you have a simple example that could help?  
Thanks  
Martin  
No problem if you are too busy

---

<div class="post-metadata">

**Author:** ![Tom\_Dixon](https://forum.xojo.com/user_avatar/forum.xojo.com/tom_dixon/32/605_2.png) [@Tom\_Dixon](https://forum.xojo.com/u/Tom_Dixon)\
**Post date:** [July 15, 2022, 11:48am UTC](https://forum.xojo.com/t/sqlite-select/71132/6 "2022-07-15T11:48:30Z")

</div>

For pictures you need to use a BLOB field and you need to convert the picture to a string to store it in that field. I use PictureToJPEGStringMBS from the MBS Picture Plugin to convert the picture to a string to insert into the database. When I retrieve the picture string I use JPEGStringToPictureMBS to restore the string to a picture object.

There are a number of threads in the forum on doing this with encode base 64 but I found the MBS plugin the easiest to use and being compressed into a jpeg uses less database space and resources. You also may want to resize your pictures so that they are never larger than a desired max height or max width.

```auto
// p is a picture, 100 is the jpeg quality
Var pstrng As String = PictureToJPEGStringMBS(p,100)
// Store the string into the DB

```

```auto
// convert the string back to a picture after retrieving it from the DB
Var p As Picture = JPEGStringToPictureMBS(dbstrng)
// Use the picture

```
