SQLite3“忘记”使用外键(SQLite3 “forgets” to use foreign keys)
我正在使用Ruby和SQLite3,并且我试图在Sqlite3中使用外键很不幸成功。 根据
sqlite3 --version
,版本3.7.13被安装。 据我所知,Sqlite3从版本3.6.x开始支持外键。我知道外键默认是关闭的,必须用
PRAGMA foreign_keys = ON;
激活PRAGMA foreign_keys = ON;
。 在我的Ruby db-create-script中,我正在做这样的事情:sql = <<-SQL PRAGMA foreign_keys = ON; CREATE TABLE apps ( id .... ); CREATE TABLE requests ( ... app_id INTEGER NOT NULL, FOREIGN KEY(app_id) REFERENCES apps(id), ); ... SQL db.execute_batch(sql)
不幸的是,我可以愉快地将行插入带有未知app-id的
requests
,它可以工作,但当然不应该。有趣的是:直接使用sqlite3 shell,我可以观察到以下行为:
$ sqlite3 database.db sqlite> PRAGMA foreign_keys = ON; sqlite> PRAGMA foreign_keys; 1 // as expected sqlite> .quit $ sqlite3 database.db sqlite> PRAGMA foreign_keys; 0 // off ?!
在不退出sqlite3外壳的情况下,外键在激活它们(并且不退出外壳程序)后工作, 我不允许插入具有未知app_id的行。
I'm using Ruby with SQLite3 and my attempts to use foreign keys in Sqlite3 were unfortunately not successful. According to
sqlite3 --version
, version 3.7.13 is installed. As far as I know, Sqlite3 supports foreign keys since version 3.6.x.I know that foreign keys are deactivated by default and have to be activated with
PRAGMA foreign_keys = ON;
. In my Ruby db-create-script, I'm doing something like this:sql = <<-SQL PRAGMA foreign_keys = ON; CREATE TABLE apps ( id .... ); CREATE TABLE requests ( ... app_id INTEGER NOT NULL, FOREIGN KEY(app_id) REFERENCES apps(id), ); ... SQL db.execute_batch(sql)
Unfortunately, I can happily insert rows into
requests
with unknown app-ids, it works, but of course it shouldn't.Interesting: using the sqlite3 shell directly, I can observe the following behaviour:
$ sqlite3 database.db sqlite> PRAGMA foreign_keys = ON; sqlite> PRAGMA foreign_keys; 1 // as expected sqlite> .quit $ sqlite3 database.db sqlite> PRAGMA foreign_keys; 0 // off ?!
Without quitting the sqlite3 shell, foreign keys are working after activating them (and not quitting the shell) and I'm not allowed to insert rows with unknown app_ids.
原文:https://stackoverflow.com/questions/15301643
最满意答案
快速解决
我有类似的问题,我解决它做下列事情
- 导航到jenkins>管理jenkins>进程内脚本批准
- 有一个悬而未决的命令,我不得不批准。
备选方案1:禁用沙箱
正如本文深入解释的那样,groovy脚本默认在沙箱模式下运行。 这意味着groovy方法的一个子集允许在没有管理员批准的情况下运行。 也可以在沙盒模式下运行脚本,这意味着整个脚本需要一次由管理员批准。 这防止用户在当时批准每条线路。
在没有沙箱的情况下运行脚本可以通过在脚本下方的项目配置中取消选中此复选框来完成:
备选方案2:禁用脚本安全性
正如本文解释的那样,也可以完全禁用脚本安全。 首先安装宽容脚本安全插件,并在此之后更改您的jenkins.xml文件添加此参数:
-Dpermissive脚本-security.enabled =真
所以你jenkins.xml看起来像这样:
<executable>..bin\java</executable> <arguments>-Dpermissive-script-security.enabled=true -Xrs -Xmx4096m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=80 --webroot="%BASE%\war"</arguments>
确保你在做什么,如果你实现这个!
Quickfix
I had similar issue and I resolved it doing the following
- Navigate to jenkins > Manage jenkins > In-process Script Approval
- There was a pending command, which I had to approve.
Alternative 1: Disable sandbox
As this article explains in depth, groovy scripts are run in sandbox mode by default. This means that a subset of groovy methods are allowed to run without administrator approval. It's also possible to run scripts not in sandbox mode, which implies that the whole script needs to be approved by an administrator at once. This preventing users from approving each line at the time.
Running scripts without sandbox can be done by unchecking this checkbox in your project config just below your script:
Alternative 2: Disable script security
As this article explains it also possible to disable script security completely. First install the permissive script security plugin and after that change your jenkins.xml file add this argument:
-Dpermissive-script-security.enabled=true
So you jenkins.xml will look something like this:
<executable>..bin\java</executable> <arguments>-Dpermissive-script-security.enabled=true -Xrs -Xmx4096m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=80 --webroot="%BASE%\war"</arguments>
Make sure you know what you are doing if you implement this!
相关问答
更多-
快速解决 我有类似的问题,我解决它做下列事情 导航到jenkins>管理jenkins>进程内脚本批准 有一个悬而未决的命令,我不得不批准。 备选方案1:禁用沙箱 正如本文深入解释的那样,groovy脚本默认在沙箱模式下运行。 这意味着groovy方法的一个子集允许在没有管理员批准的情况下运行。 也可以在沙盒模式下运行脚本,这意味着整个脚本需要一次由管理员批准。 这防止用户在当时批准每条线路。 在没有沙箱的情况下运行脚本可以通过在脚本下方的项目配置中取消选中此复选框来完成: 备选方案2:禁用脚本安全性 正如 ...
-
如果你只是避免实例化StringParameterValue你可以让它工作,因为正如David M. Karr提到的管道沙箱是相当严格的。 相反,只需在调用作业时使用简单变量,如下所示: def subnet = "" if(ipaddr == '192.168.1.1') { subnet = '255.255.255.0' echo subnet } stage ('Stage A'){ build job: 'jobA', parameters: [ ...
-
Groovy Date()对象不能在Jenkins管道中被创建(Groovy Date() object cannot be creted in Jenkins pipeline)[2022-09-13]
这个输出意味着它不是白名单的方法/类: org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new java.util.Date 您可以通过jenkinsurl / scriptApproval批准它,也可以将其更改为支持的内容。 println currentBuild.getTimeInMillis() println currentBuild.getSta ... -
Jenkins的Docker插件错误:脚本不允许使用方法(Docker Plugin for Jenkins error: Scripts not permitted to use method)[2023-11-01]
我能够通过从这个Docker 镜像在我的奴隶上安装docker-io并使用一个单独的Docker主机来解决这个问题,该主机可以为我需要进行的调用提供服务来构建,运行并将我的docker镜像推送到我的注册表。 我最终使用以下脚本来解决此问题: docker.withServer(DOCKER_MACHINE_HOSTNAME) { def image = docker.build(DOCKER_TAG, '.') // Test container then stop and remove ... -
如果您想中止程序的异常处理,则可以使用流水线步骤error来停止流水线执行并发生错误。 示例: try { // Some pipeline code } catch(Exception e) { // Do something with the exception error "Program failed, please read logs..." } 如果你想停止你的管道成功状态,你可能想要有某种布尔值指示你的管道必须停止,例如: boolean continuePipeline ...
-
如何将生成参数添加到jenkins multibranch管道?(How to add build parameters to jenkins multibranch pipeline?)[2020-01-20]
你应该使用properties步骤。 另请看这里在Stackoverflow:我如何使用jenkins管道属性步骤? 。 这是我的问题,我已经了解到,即使片段生成器不这样做,您也需要明确添加括号。 例: properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [[$class: 'StringParameterDefinition', name: 'myparam', defaultValue: 'default ... -
从jenkins管道groovy脚本加载配置文件的推荐方法(Recommended way of loading config file from jenkins pipeline groovy script)[2023-11-16]
尝试使用JsonSlurper : def config = new JsonSlurper().parse(new File("config.json")) Try using the JsonSlurper: def config = new JsonSlurper().parse(new File("config.json")) -
要在构建路径中使用groovy-all-2.3.7.jar是不够的,它必须位于webapp的WEB-INF/lib文件夹中,或者也可以位于Tomcat的lib文件夹中。 To have the groovy-all-2.3.7.jar in the build path is not enough, it has to be in the WEB-INF/lib folder of the webapp, or in the Tomcat's lib folder, too.
-
Jenkins管道groovy.lang.MissingPropertyException(Jenkins pipeline groovy.lang.MissingPropertyException)[2023-07-20]
在这种groovy字符串中遇到麻烦: sh ".... $bitbucketRepoName.git ...." 在这种情况下groovy它试图访问变量bitbucketRepoName属性git 只需改变它: sh ".... ${bitbucketRepoName}.git ...." trouble in this kind of groovy string: sh ".... $bitbucketRepoName.git ...." in this case groovy it tries t ... -
您不能混合Pipeline DSL和Job DSL 。 那些是完全不同的东西。 自版本1.100起, XUnit 插件内置支持Pipeline DSL,有关详细信息,请参阅JENKINS-27240 。 因此,您无需尝试在Pipeline脚本中嵌入Job DSL脚本。 You can not mix Pipeline DSL and Job DSL. Those are completely different things. The XUnit Plugin has built-in support fo ...