Question

i have a table in sqlite with table name birthday,and rows >id,name,day,month. i get from my array the system date and convert it to this (day/month). im using the dblib from andre to retrieve it like the code bellow

 on mouseUp
  put the system date into tdate
   convert tDate to short system date
convert tDate to dateitems 
  --put (the item 3 of tDate) & "/" & (the item 2 of tDate) into field "birthday"
  put (the item 3 of tDate) & "/" & (the item 2 of tDate) into today

  dbcolumns "day,month"
  put dbGet("giortes") into myRecords
  repeat for each key tKey in myRecords
    put myRecords[tKey]["day"] &"/"& myRecords[tKey]["month"] & cr after myGiortes[1]
  end repeat
put 0 into check
put false into verify
repeat for each line tempItem in myGiortes[1]
   add 1 to t
   if tempItem = today then
      put true into check
      exit repeat
   end if
end repeat
if check then
  --!! test
  put today into fld tfld

end if

end mouseUp

so i get the result in the array like this 12/08. is possible to match the result with a row in the sqlite? I have reproduce the code above. i get the results from the array and match it with system date converted. now i want to get all the Row from the database ;)

Was it helpful?

Solution

Your code snipper it very brief. It might help if you posted the dbGet function, for example. Are you sure that myRecords is an array? You can check this with

if myRecords is an array then

It isn't clear which row and column delimiters you use, but I assume they are linefeed and tab. You might do the following:

dbcolumns "day,month"
put dbGet("giortes") into myRecords
if myRecords is not an array then split myRecords by return and tab
repeat for each key tKey in myRecords
  put myRecords[tKey]["day"] &"/"& myRecords[tKey]["month"] & cr after myGiortes[1]
end repeat

Obviously, this only works if myRecords not being an array is the culprit. If there is a problem with your SQL syntax, myRecords could be empty or contain different keys.

If myRecords actually is an error and you just want to find the tkey's for which day=12 and month=8, you can adjust your repeat loop:

repeat for each key tKey in myRecords
  if myRecords[tKey]["day"] is 12 and myRecords[tKey]["month"] is 8 then
    put myRecords[tKey]["day"] &"/"& myRecords[tKey]["month"] & cr after myGiortes[1]
  end if
end repeat

You might also do this directly using the correct SQL syntax on the database:

put "SELECT * FROM giortes WHERE day='12' AND month='8'" into mySQL
// I start variables with "my", it isn't a reference to MySQL
put revDataFromQuery(cr,tab,gDatabaseID,mySQL) into myGiortes
if myGiortes begins with "revdberr" then
  beep
  answer error myGiortes
else
  split myData by cr and tab
end if

You also need to make a connection with revOpenDatabase. For this, you need to know the path to the SQLite file.

put revOpenDatabase("sqlite",mySQliteFilePath,,,) into gDatabaseID

After this line, you can run the previous code snipper. Declare gDatabaseID as a global variable at the top of the script.

Update 1

If you prefer to use Andre's database, you can use the dbWhere command:

set the itemDel to slash
put item 1 of the date into myMonth
put item 2 of the date into myDay
dbColumns "day,month,id" // I have added id
dbWhere "month",myMonth
dbWhere "day",myDay
put dbGet("giortes") into myGiortes
dbResetQuery

This should be sufficient to answer your question. You need no repeat loop any more. I just wonder why you would want this, because now you only get a list like:

1  12,8
2  12,8
3  12,8
etc

If you want to know the number of records, you might want to use SQLite's COUNT function instead.

Update 2

I have changed the code under "Update 1". If you are indeed just looking or the ID of a person who has his birthday today, then you can use dbColumns "id" instead of dbColumnds "day,month,id". This would make much more sense, because the sample data in my previous example are useless. If you run the modified code, you should get data similar to

1  12,8,1
2  12,8,11
3  12,8,23
etc

i.e. the last column contains the ID numbers. You could also just retrieve the ID numbers. if you do that, you get

1  1
2  11
3  23
etc

OTHER TIPS

If you are trying to find the birthday of the current user then put that id of the current user into the 'myUserId' variable and use the following dbWhere clause from Andre's framework

dbWhere "id",myUserId

Of course you may be trying to accomplish something different?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top