首页 \ 问答 \ 主数据库中的外键引用附加数据库(Foreign key in main database referencing attached database)

主数据库中的外键引用附加数据库(Foreign key in main database referencing attached database)

在SQLite3中是否有任何方法在主数据库中有一个引用附加数据库中的列的外键(反之亦然?)

我希望在多个进程之间共享附加的(只读)数据库,每个进程都有自己的(读/写)主数据库。

我像这样创建父表(在数据库'ParentDB'中):

create table Parent (id integer primary key);

现在我在主数据库中尝试这个:

attach 'parent.sqlite3' as ParentDB;
create table Child (id integer not null references Parent (id),
                    constraint PK_Child primary key (id));
insert into ParentDB.Parent (id) values (42);

当我尝试它时,它创建没有错误的外键。 现在我尝试在子表中插入一行:

insert into Child (id) values (42);

我收到这个错误:

Error: no such table: main.Parent

所以它似乎总是假设父表和子表属于同一个数据库。

外键语法也不允许您指定父表所属的数据库

有解决方法吗?


这个问题是相关的,但是这里父表和子表都在同一个附加数据库中,而我将它们放在不同的数据库中。


Is there any way in SQLite3 to have a foreign key in the main database that references columns in an attached database (or vice-versa?)

I hope to share the attached (read-only) database between multiple processes, each of which has its own (read/write) main database.

I create the parent table like this (in database 'ParentDB'):

create table Parent (id integer primary key);

Now I try this in the main database:

attach 'parent.sqlite3' as ParentDB;
create table Child (id integer not null references Parent (id),
                    constraint PK_Child primary key (id));
insert into ParentDB.Parent (id) values (42);

When I try it it creates the foreign key with no errors. Now I try to insert a row into the child table:

insert into Child (id) values (42);

And I get this error:

Error: no such table: main.Parent

So it seems it always assumes the parent and child tables belong to the same database.

Also the foreign key syntax does not allow you to specify which database the parent table belongs to.

Is there a workaround?


This question is related, but here both the parent and child tables are in the same attached database, whereas I have them in separate databases.


原文:https://stackoverflow.com/questions/22289837
更新时间:2023-03-23 06:03

最满意答案

我不确定这是否适用于非root设备,但是:

echo $(adb shell ps | grep com.android.phone | awk '{ system("adb shell cat /proc/" $2 "/stat");}' | awk '{print $14+$15;}')

这将打印进程使用的用户模式jiffies和内核模式jiffies的总和。 将com.android.phone替换为您感兴趣的进程名称。


I'm not sure if this would work on a non-rooted device, but:

echo $(adb shell ps | grep com.android.phone | awk '{ system("adb shell cat /proc/" $2 "/stat");}' | awk '{print $14+$15;}')

This would print the sum of the user mode jiffies and kernel mode jiffies used by the process. Replace com.android.phone with the name of the process you're interested in.

相关问答

更多
  • 这些值是以时钟周期为单位的CPU和系统时间。 该定义可以在桌面系统的man 5 proc文本中找到: utime %lu Amount of time that this process has been scheduled in user mode, measured in clock ticks (divide by sysconf(_SC_CLK_TCK). This inc ...
  • 非常简单,它可以像这样工作: 用一些合理的小等待时间(可能是100ms)创建一个定期等待定时器。 通过调用一次GetProcessTimes为每个相关进程获取“最后”值。 永远循环,阻止定时器。 每次你醒来: 如果 GetProcessAffinityMask返回0,则调用SetProcessAffinityMask(old_value) 。 这意味着我们在上一次迭代中暂停了这一过程,现在我们给它一次再次运行的机会。 否则调用GetProcessTimes来获取“当前”值 调用GetSystemTimeAs ...
  • 从这次讨论中我发现在Android上获取这些信息是不可能的。 而且我在Android上使用了很多任务管理器,但没有一个没有提供这样的数据(它们只显示内存使用情况)。 更新: 看起来您的问题与此问题重复。 所以你需要做的就是分析文件/proc//stat以获得CPU使用率。 更新#2: 从源码Android top.c我发现如何在函数print_procs获取进程用法: proc->delta_time * 100 / total_delta_time From this discussion I ...
  • 至少对于linux来说,快速回答是使用getrusage以及具有更高分辨率计时器的内核。 我最初的测试给出了10ms的可怕精度的原因是因为显然64位ubuntu默认配置为100hz计时器。 The quick answer, at least for linux, is to use getrusage along with a kernel that has a higher resolution timer. The reason my initial tests gave the terrible p ...
  • 第一个问题,你被困在一个时间点,因为当你执行你的脚本时,它会捕捉当时和那里发生的事情的快照。 您正在寻找的是历史数据,因此您可以在一段时间内计算出进程的平均CPU使用率,并找出导致CPU崩溃的过程。 您是否有适当的性能监视器来跟踪各个进程的CPU使用情况? 如果您希望能够在事后找到您要查找的数字,则可能需要设置性能日志记录。 其次,我认为你误解了Measure-Object工作原理。 如果在cmdlet上运行Get-Help并检查输出,您将看到它输出GenericMeasureInfo对象。 此对象将具有您 ...
  • 当然, wait3和wait4让你wait3 。 或者(并且更便携)你可以使用getrusage(2) 。 wait3()和wait4()系统调用类似于waitpid(2),但另外返回有关rusage指向的结构中的子rusage资源使用信息。 示例: wait3 struct rusage usage; wait3(&status, 0, &usage); 示例: getrusage 当然, wait3和wait4只是一个方便。 所以你可以使用getrusage : getrusage(RUSAGE_CH ...
  • Process Uptime是在第一个线程开始和最后一个线程结束之间传递的挂钟(我认为)时间量。 您需要查看User time: 0 days 0:26:24.000 ,这就是所有这些行应该添加的内容。 要获得使用的总CPU时间,您需要执行User Time + Kernel Time Process Uptime is the amount of wall clock (I think) time that passed between the first thread starting and the ...
  • 我不确定这是否适用于非root设备,但是: echo $(adb shell ps | grep com.android.phone | awk '{ system("adb shell cat /proc/" $2 "/stat");}' | awk '{print $14+$15;}') 这将打印进程使用的用户模式jiffies和内核模式jiffies的总和。 将com.android.phone替换为您感兴趣的进程名称。 I'm not sure if this would work on a no ...
  • 错误说明 我怀疑您使用/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq中的值作为hertz值。 这是不正确的,因为该文件为您提供CPU硬件时钟频率,但您必须使用Linux内核时钟频率作为hertz值。 CPU硬件时钟和Linux内核时钟不同。 Android运行的Linux内核有自己的定时器(时钟),它以一定的频率更新; 此计时器更新的频率是内核赫兹( HZ )值。 由于历史原因 ,Linux proc和sys文件中列出的时钟刻度值通过Linux内核 ...
  • 这是因为子进程在用户空间或内核空间中花费的时间。 sleep只是暂停调用进程,并且根本不会导致任何CPU使用。 相反,让您的子进程执行某些操作,您将看到CPU时间。 例如,有一个名为myscript的脚本: #!/bin/bash for((i=0;i<1000000;i++)); do echo hi >/dev/null done 并将其作为子进程执行,它将显示一些CPU使用情况。 That's because there's time spent by the child process ...

相关文章

更多

最新问答

更多
  • 您如何使用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)