gpt4 book ai didi

sqlite - Livecode中基于云的SQLite用于集中式数据库

转载 作者:行者123 更新时间:2023-12-03 17:54:19 25 4
gpt4 key购买 nike

我正在开发一个livecode应用程序。在该应用程序中,我需要使用基于云的sqlite,这意味着它应该对所有用户共享。目前,我正在将sqlite用于本地,但我认为它仅适用于一个设备应用程序,尽管每个用户都将拥有自己的数据库。但是我想要与所有用户共享一个数据库。有人建议我对远程数据库使用JSON解析。
http://lessons.runrev.com/s/lessons/m/4071/l/7003-connecting-to-a-mysql-database。可以从Web上通过url,用户名和密码访问此mysql数据库。那里没有任何Json解析。对于Sqlite是否可以?
请帮忙

最佳答案

如果为SQLite编写服务器,则可以将其与多个客户端一起使用。请注意,仅使用MySQL或PostgreSQL服务器可能会更容易,即使它们的强类型也很烦人。

对于联网的SQLite,您需要一个通过套接字连接从客户端接收数据的服务器。因此,基本上,您将只有一个LiveCode程序,该程序可以通过网络传递SQL查询。一个非常简单的例子(未经测试):

服务器:

on mouseUp
accept connections on port 8080 with message "queryMessage"
end mouseUp

on queryMessage theIP
read from socket theIP until return
put it into mySQL
delete char -1 of mySQL --remove trailing return that was added for network protocol
put revOpenDatabase("SQLite","path/to/myDatabase.sqlite",,,) into connectionID
put revDataFromQuery(,,connectionID,mySQL) into myResult
revCloseDatabase connectionID
write length(myResult) & return & myResult to socket theIP --no return needed, length based
close socket theIP
end queryMessage


客户:

on mouseUp
-- make sure to know what IP the server is running from!
-- the number after ":" is the port
put "localhost:8080" into myIP
open socket to myIP
write "SELECT * FROM tableName" & return to socket myIP
read from socket myIP until return
put it into returnStringLength
read from socket myIP for returnStringLength chars
put it into field "the sql query result"
close socket myIP
end mouseUp


您还需要:


处理诸如INSERT,PRAGMA等命令的方法(基本上是revExecuteSQL)
SQL错误报告/处理
套接字错误报告/处理
如果公众可以访问,则需要安全!
记录谁在查询以及正在发生什么


我只对4-8个客户使用了这种方法,所以我不知道它对于较大的客户群的扩展能力。请注意,在这种情况下,“服务器”不在共享的Web主机(如网页)上运行,而是在同一局域网中的PC上运行“普通”程序(示例旨在与客户端在同一台PC上运行)。通过Internet进行此操作通常需要您转发路由器或防火墙上的端口,因此设置起来有点困难,但也是可以的。

确保在字典中查找示例中使用的命令。

关于sqlite - Livecode中基于云的SQLite用于集中式数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18072590/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com