Okay. I’m learning more and more. I decided to create an extension method to illustrate what I was originally asking about.
First, I created the Extension Method:
Signature: Global Function FindAll(Extends values() as String, searchCriteria as String, ByRef err as DatabaseException) As RowSet
// in-memory sqlite db
var rs as RowSet
dbsource = new SQLiteDatabase
Try
dbsource.Connect
dbsource.ExecuteSQL("CREATE TABLE test(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
Var stmt As SQLitePreparedStatement = dbsource.Prepare("insert into test (name) values(?)")
dbsource.BeginTransaction
for each value as String in Values
stmt.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)
stmt.Bind(0, value)
stmt.ExecuteSQL(value)
next
dbsource.CommitTransaction
stmt = dbsource.Prepare("select name from test where name like ?")
stmt.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)
stmt.Bind(0, searchCriteria)
rs = stmt.SelectSQL
Catch e As DatabaseException
err = e
End Try
dbsource.close
return rs
Then in a Button_Pressed Event, I added this code:
var myArray() as String
for x as integer = 1 to totalRows
myArray.Add("Number: " + x.ToString)
next
var err as DatabaseException
var rs as RowSet
rs = myArray.FindAll("%43%", err)
if rs <> Nil And rs.RowCount > 0 then
ListBox1.RemoveAllRows
for row as Integer = 1 to rs.RowCount
var itm as String = rs.ColumnAt(0).StringValue
ListBox1.AddRow(itm)
rs.MoveToNextRow
next
end if
Everything works fine. Keep in mind that I plan to make this a bit more efficient and clean things up a bit, but ultimately the key statement here is: rs = MyArray.FindAll(SQLSearchCriteria).
Just ignore the ‘err’ parameter for now. I was getting a DB error and I decided to pass it back ByRef so that I could read it.
I could have gone with a Delegate here as well, but I kind of prefer the syntax of the Extension Method.
Having Xojo add a Find and/or FindAll method associated with arrays would be nice so that we can then specify the search criteria and pass a Function Pointer to it which would do the work.
But it’s cool. I’ve learned much going through this motion.
Thanks for all of the feedback.