Database livecode从sqlite检索记录

Database livecode从sqlite检索记录,database,sqlite,livecode,Database,Sqlite,Livecode,我在sqlite中有一个表,表名为生日,行>id,名称,日期,月份。 我从数组中获取系统日期,并将其转换为该日期(天/月)。 我使用andre的dblib来检索它,就像下面的代码一样 on mouseUp put the system date into tdate  convert tDate to short system date convert tDate to dateitems --put (the item 3 of tDate) & "/" & (

我在sqlite中有一个表,表名为生日,行>id,名称,日期,月份。 我从数组中获取系统日期,并将其转换为该日期(天/月)。 我使用andre的dblib来检索它,就像下面的代码一样

 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
所以我在数组中得到的结果如下12/08。 是否可以将结果与sqlite中的一行匹配? 我复制了上面的代码。 我从数组中获取结果,并将其与转换的系统日期匹配。
现在我想从数据库中获取所有行;)

您的代码非常简短。例如,如果发布dbGet函数,可能会有所帮助。您确定myRecords是一个数组吗?你可以跟我核对一下

if myRecords is an array then
不清楚您使用的是哪一行和哪一列分隔符,但我假定它们是换行符和制表符。您可以执行以下操作:

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
显然,这只有在myRecords不是数组的情况下才有效。如果SQL语法有问题,myRecords可能为空或包含不同的键

如果myRecords实际上是一个错误,并且您只想找到tkey的日期=12,月份=8,则可以调整重复循环:

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
您也可以在数据库上使用正确的SQL语法直接执行此操作:

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
您还需要与revOpenDatabase建立连接。为此,您需要知道SQLite文件的路径

put revOpenDatabase("sqlite",mySQliteFilePath,,,) into gDatabaseID
在这一行之后,您可以运行前面的代码snipper。在脚本顶部将gDatabaseID声明为全局变量

更新1

如果希望使用Andre的数据库,可以使用dbWhere命令:

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
这应该足以回答您的问题。你不再需要重复循环了。我只是想知道为什么你会想要这个,因为现在你只会得到这样一个列表:

1  12,8
2  12,8
3  12,8
etc
如果您想知道记录的数量,可能需要使用SQLite的COUNT函数

更新2

我已经更改了“更新1”下的代码。如果您确实只是查看今天过生日的人的ID,那么您可以使用
dbColumns“ID”
而不是
dbColumnds“day,month,ID”
。这将更有意义,因为我前面示例中的示例数据是无用的。如果您运行修改后的代码,您应该会得到与

1  12,8,1
2  12,8,11
3  12,8,23
etc
i、 e.最后一列包含ID号。您还可以检索ID号。如果你那样做,你就会

1  1
2  11
3  23
etc

如果您试图查找当前用户的生日,则将当前用户的id放入'myUserId'变量中,并使用Andre框架中的以下dbWhere子句

dbWhere "id",myUserId

当然,您可能正在尝试完成一些不同的任务?

我复制了上面的代码,下面是函数的链接。[链接]我会看一看链接,但在Stackoverflow上,不链接到代码,而是将其全部包含在问题中被认为是一个好习惯。链接是我在代码中使用的函数。andre的代码是librarys,因此我可以这样做,因为它被锁定。只要看看我在原始帖子中编辑的代码,如果有帮助的话..我已经在你的帖子上看到了更新,这是在数据库中进行staic搜索的默认答案..就像我说的日期是系统日,所以是随机的[/b]将是(12/08,12/09或02/02),这是我的问题..用dbwhere或sql检索特定的记录是可以的,但我们如何处理随机的?不确定这里的“随机”是什么意思。您想在数据库中查找今天的日期,还是真的想要随机日期?