如果您为 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 个客户使用过这种方法,所以我不知道它是否适用于更大的客户群。请注意,在这种情况下,“服务器”不是在共享的虚拟主机(如网页)上运行,而是在同一本地网络中的 pc 上的“普通”程序(示例适合在与客户端相同的 pc 上运行)。通过 Internet 执行此操作通常需要您在路由器或防火墙上转发端口,因此设置起来有点困难,但也是可能的。
确保在字典中查找示例中使用的命令。