首页 \ 问答 \ 如果在SQLite中使用外键,则创建表失败(Create table fails if foreign keys are used in SQLite)

如果在SQLite中使用外键,则创建表失败(Create table fails if foreign keys are used in SQLite)

我真的不知道为什么这个PHP代码不创建三个表。 第一和第二都很好。 但第三个失败了。 第三个与第二个非常相似,但在外键定义之后有另一个字段。 我在这做错了什么?

$db = new \PDO("sqlite:d:/temp/test_db.sqlite");
$db->exec("PRAGMA foreign_keys = 'ON'");


$statement = $db->query("CREATE TABLE  IF NOT EXISTS customers(
  id TEXT PRIMARY KEY NOT NULL , 
  name TEXT  
)");

$statement->execute();

$statement = $db->query("CREATE TABLE  IF NOT EXISTS appointments (
  id TEXT PRIMARY KEY NOT NULL , 
  customer TEXT   , 
  FOREIGN KEY (customer) REFERENCES customers(id)  
)");

$statement->execute();


$statement = $db->query("CREATE TABLE  IF NOT EXISTS appointment (
  id TEXT PRIMARY KEY NOT NULL ,  
  customer TEXT   , 
  FOREIGN KEY (customer) REFERENCES customers(id),
  nextfield TEXT
)");

$statement->execute();

I seriously have no idea why this php code is not creating three tables. The first and second are fine. But the third fails. The third is very similar to the second but has another field after the foreign key definition. What am I doing wrong here?

$db = new \PDO("sqlite:d:/temp/test_db.sqlite");
$db->exec("PRAGMA foreign_keys = 'ON'");


$statement = $db->query("CREATE TABLE  IF NOT EXISTS customers(
  id TEXT PRIMARY KEY NOT NULL , 
  name TEXT  
)");

$statement->execute();

$statement = $db->query("CREATE TABLE  IF NOT EXISTS appointments (
  id TEXT PRIMARY KEY NOT NULL , 
  customer TEXT   , 
  FOREIGN KEY (customer) REFERENCES customers(id)  
)");

$statement->execute();


$statement = $db->query("CREATE TABLE  IF NOT EXISTS appointment (
  id TEXT PRIMARY KEY NOT NULL ,  
  customer TEXT   , 
  FOREIGN KEY (customer) REFERENCES customers(id),
  nextfield TEXT
)");

$statement->execute();

原文:https://stackoverflow.com/questions/48019564
更新时间:2022-12-11 19:12

最满意答案

我不知道这是否可行,因为我所做的大部分工作都是在嵌入式系统中进行的,在这些嵌入式系统中我甚至不需要触摸操作系统。 但是,下面是可能的吗?

编译你的程序时,在最后留下一些额外的空间(比如说8个字节),全部设置为0.当你的应用程序运行时,它会获取这些字节,如果它们都是0,用当前时间替换它们(这就是这个部分我不确定,操作系统是否允许你这么做?如果不是这样,可能会有一些使用多个进程的解决方法),否则,如果时间差大于30天,它会通知用户试用期已结束。

当然,这种方法很容易重置系统时钟。


I don't know if this is possible, as most work I've done has been with embedded systems in which I don't even need to touch the operating system. But would the following be possible?

When compiling your program, leave some extra space at the end (say, 8 bytes), all set to 0. When your application is run, it fetches those bytes and if they're all 0, replaces them with the current time (That's the part I'm not sure about. Does the OS let you do that? If not, there might be some work-arounds using multiple processes.), otherwise, if the time difference is greater than 30 days, it notifies the user that the trial period has ended.

Of course, that method would be vulnerable to resetting the system clock.

相关问答

更多
  • 目前大多数开发人员使用以下3种技术之一完成此任务。 第一种方法很容易规避,首次运行应用程序将日期/时间保存到文件,数据库或共享首选项,并且每次在检查后运行应用程序,以查看试用期是否已结束。 这很容易规避,因为卸载和重新安装将允许用户有另一个试用期。 第二种方法难以规避,但仍然可以绕过。 使用硬编码的定时炸弹。 基本上,通过这种方法,您将很难编写试用的结束日期,下载和使用该应用程序的所有用户将停止在同一时间使用该应用程序。 我使用这种方法,因为它很容易实现,而在大多数情况下,我只是不想经历第三种技术的麻烦。 ...
  • 我不知道这是否可行,因为我所做的大部分工作都是在嵌入式系统中进行的,在这些嵌入式系统中我甚至不需要触摸操作系统。 但是,下面是可能的吗? 编译你的程序时,在最后留下一些额外的空间(比如说8个字节),全部设置为0.当你的应用程序运行时,它会获取这些字节,如果它们都是0,用当前时间替换它们(这就是这个部分我不确定,操作系统是否允许你这么做?如果不是这样,可能会有一些使用多个进程的解决方法),否则,如果时间差大于30天,它会通知用户试用期已结束。 当然,这种方法很容易重置系统时钟。 I don't know if ...
  • 我认为这取决于应用程序类型。 我认为时间限制是最好的,如果: 没有保存在应用程序中的数据,如果我不知道它将无法使用。 这是一种日常应用,而不是仅仅使用一次或两次。 我认为功能有限是最好的,如果: 该应用程序仅使用一次或在短时间内使用。 应用程序可以被限制在能够证明其权力的方式,但不能提供有用的结果。 我将其标记为社区wiki,随时将其添加到列表中。 I think that it depends on the application type. I think time limited is best if ...
  • 由于您不想让用户再次获得试用版,如果他重新安装应用程序,您将不得不使用第三种技术将数据发送到服务器,因为这是持续计算按钮点击次数和通过应用安装将其绑定到设备。 因此,不使用时间,您可以保留服务器上单击按钮的次数。 此外,您可以在应用程序到期之前配置您希望允许的按钮单击次数,而不是在应用程序中进行硬编码。 如果您不想运行自己的服务器,则使用Parse来存储按钮的点击次数和用户ID。 整合非常容易。 https://parse.com/docs/android/guide#getting-started Sin ...
  • 您可以使用Zend Encoder或Ioncube加密源,或对它们进行模糊处理。 但事实是,上面的所有内容都可以修补。 因此,如果目标用户经验足够 - 他们可以删除您的试用期检查。 You can encrypt your sources using Zend Encoder or Ioncube, or obfuscate them. But the fact is that everything from above can be patched. So if target user is experi ...
  • 就像您所说的那样 - 第一优先级是有关试用的数据保存在用户无法访问的远程服务器上。 一旦用户在新设备上安装应用程序,然后在数据库中搜索密钥,您就可以保留功能数据库并分配唯一(主)密钥。 如果找到它,请激活试用功能并从数据库中删除该条目,以便将来不再有资格进行试用促销。 这还允许您手动添加条目,以防用户抱怨或部分代码出现故障并阻止用户体验该功能。 编辑:本机,Android支持SQLite数据库,所以我建议你在设计数据库时遵循他们的指导。 至于管理数据库和查询它,我使用本教程开始学习它。 但是,我认为最好是在 ...
  • 我收到了paypal论坛对这个问题的回复。 我将此添加为答案,因为这将有助于其他开发人员。 也是IPN的良好起点 回应是, “如果您正在使用PDT,则不会发送任何内容,因为没有付款。只有在您付款时才会发回信息。我建议使用IPN .rm变量和PDT都取决于买方返回您的网站。如果买家没有返回,例如他们的浏览器窗口意外崩溃和关闭,或者他们只是关闭它,将不会发回任何信息并且它将丢失。这就是使用rm变量和PDT的原因更多用于创建动态收据.IPN更多地用于更新您的系统,因为它不依赖于买家返回您的网站。“ “如果您需要, ...
  • 我会尝试尽可能少地存储在客户端PC上并使用Web服务分布式解决方案。 当然还是hackable,但至少在客户端上没有任何东西可以找到或编辑,你可以从你的服务器控制谁启动应用程序。 当然,这假设客户端PC应该在线以使应用程序正常工作。 肯定是可以改进的,但正如你所说,没有完美的解决方案。 I would try to store as little as possible on the client pc and use a web service distributed solution. Still ha ...
  • Windows注册表中包含注册表值包括安装日期和其他详细信息。 我不确定你想做什么但主要是这就是他们所做的。 即使在卸载软件之后,应用程序的注册表值仍留在注册表中。 因此,要回答您的问题,应用程序使用注册表条目即使在您删除软件并尝试重新安装后,也知道您的试用期已过期。 There are registry values written in the windows registry Including the dates for installation and other details. Am not ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)