LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-03-2008, 09:46 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
[python] sqlite: Can you combine two database files?


I have a database for all the files on a disk. I have several disks. Sometimes I want to rescan one disk but not the others, so I keep each disk's database in its own file, i.e. disk1.db, disk2.db, disk3.db, etc.

is there a quick way to combine all these databases so that I can make one SELECT call for all db's? I know I could pre-process all the db's into one memory db by doing a "select *" on each & then inserting the results into the memory db, but I'm hoping to find something a little quicker/easier/ more efficient/correct.

If it matters, I'm doing this in python2.5 with the sqlite3 module.

Thanks.
 
Old 09-04-2008, 04:46 PM   #2
jcookeman
Member
 
Registered: Jul 2003
Location: London, UK
Distribution: FreeBSD, OpenSuse, Ubuntu, RHEL
Posts: 417

Rep: Reputation: 33
If this is a one-off, why don't you just dump the databases and import them into the preferred database?
 
Old 09-04-2008, 04:56 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
It's not a one-off. The system is a bit more complex than I alluded to (the "disks" are actually multi-terabyte arrays and the db files may be generated by deamons at regular intervals), but principle is the same - merge two or more dbs together & use the combined db for select statements.

At the end of the day, I may still do what you suggested, as it's the obvious solution (even if done on the fly), but I was hoping for something a little more clever or by design.
 
Old 09-10-2008, 04:57 PM   #4
nesba737
LQ Newbie
 
Registered: Sep 2008
Posts: 3

Rep: Reputation: 0
I was/am looking at similar problem
 
Old 09-10-2008, 04:58 PM   #5
nesba737
LQ Newbie
 
Registered: Sep 2008
Posts: 3

Rep: Reputation: 0
See http://souptonuts.sourceforge.net/re..._tutorial.html
 
Old 09-10-2008, 06:54 PM   #6
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
I'm not certain if sqlite supports the schema naming convention within the select (MySQL does) so you would do do something like SELECT * FROM disk1db.name, disk2db.name; However I'm guessing that you would then end up with a Cartesian join, can't you just tell I've never done this. Probably because I would have approached the problem differently by adding an extra field in the table that would identify the disk. That way a SELECT * FROM diskdb WHERE disk = disk1 would return the details from one disk and SELECT * FROM diskdb would return everything.
 
Old 09-11-2008, 06:59 AM   #7
nesba737
LQ Newbie
 
Registered: Sep 2008
Posts: 3

Rep: Reputation: 0
Keeping an extra column to identify disk/host would not solve my problem. What I need to do, ideally, is "attach" (combine) tables/databases/database_files from geographically/logically distributed hosts (so that I don't have to continually transfer large data from the remote hosts to the central host).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SQlite problems: attempt to write a readonly database brokenpromises Linux - Server 3 09-10-2013 10:52 AM
Sqlite Database image malformed ravindranvasudevan Programming 6 08-10-2009 03:37 AM
howto build python with sqlite support? b3rx Slackware 4 12-03-2007 07:57 PM
SQLite database security - doesn't exist? vharishankar Linux - Security 2 11-30-2005 08:40 PM
SQLite database backup ddpicard Linux - Software 2 11-01-2004 06:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration