SQL update: two diffs left, in family and place
svn: r12935
This commit is contained in:
parent
65f72560d1
commit
0a476e2a3c
@ -1,6 +1,6 @@
|
|||||||
# Gramps - a GTK+/GNOME based genealogy program
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
#
|
#
|
||||||
# Copyright (C) 2008 Douglas S. Blank
|
# Copyright (C) 2008 Douglas S. Blank <doug.blank@gmail.com>
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -18,27 +18,41 @@
|
|||||||
#
|
#
|
||||||
# $Id$
|
# $Id$
|
||||||
#
|
#
|
||||||
|
|
||||||
|
"Export to SQLite Database"
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# python modules
|
# Standard Python Modules
|
||||||
#
|
#
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
from gettext import ngettext
|
||||||
import sqlite3 as sqlite
|
import sqlite3 as sqlite
|
||||||
import re
|
import time
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Set up logging
|
||||||
|
#
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger(".ExportSql")
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# GRAMPS modules
|
# GRAMPS modules
|
||||||
#
|
#
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
import gen.lib
|
|
||||||
from gen.plug import PluginManager, ExportPlugin
|
from gen.plug import PluginManager, ExportPlugin
|
||||||
import DateHandler
|
|
||||||
from gui.utils import ProgressMeter
|
|
||||||
import ExportOptions
|
import ExportOptions
|
||||||
from Utils import create_id
|
from Utils import create_id
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Export functions
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
def lookup(index, event_ref_list):
|
def lookup(index, event_ref_list):
|
||||||
"""
|
"""
|
||||||
Get the unserialized event_ref in an list of them and return it.
|
Get the unserialized event_ref in an list of them and return it.
|
||||||
@ -60,6 +74,7 @@ def makeDB(db):
|
|||||||
db.query("""drop table event;""")
|
db.query("""drop table event;""")
|
||||||
db.query("""drop table family;""")
|
db.query("""drop table family;""")
|
||||||
db.query("""drop table repository;""")
|
db.query("""drop table repository;""")
|
||||||
|
db.query("""drop table repository_ref;""")
|
||||||
db.query("""drop table date;""")
|
db.query("""drop table date;""")
|
||||||
db.query("""drop table place;""")
|
db.query("""drop table place;""")
|
||||||
db.query("""drop table source;""")
|
db.query("""drop table source;""")
|
||||||
@ -77,6 +92,7 @@ def makeDB(db):
|
|||||||
db.query("""drop table location;""")
|
db.query("""drop table location;""")
|
||||||
db.query("""drop table attribute;""")
|
db.query("""drop table attribute;""")
|
||||||
db.query("""drop table url;""")
|
db.query("""drop table url;""")
|
||||||
|
db.query("""drop table datamap;""")
|
||||||
|
|
||||||
db.query("""CREATE TABLE note (
|
db.query("""CREATE TABLE note (
|
||||||
handle CHARACTER(25),
|
handle CHARACTER(25),
|
||||||
@ -193,6 +209,14 @@ def makeDB(db):
|
|||||||
marker1 TEXT,
|
marker1 TEXT,
|
||||||
private BOOLEAN);""")
|
private BOOLEAN);""")
|
||||||
|
|
||||||
|
db.query("""CREATE TABLE repository_ref (
|
||||||
|
handle CHARACTER(25),
|
||||||
|
ref CHARACTER(25),
|
||||||
|
call_number TEXT,
|
||||||
|
source_media_type0 INTEGER,
|
||||||
|
source_media_type1 TEXT,
|
||||||
|
private BOOLEAN);""")
|
||||||
|
|
||||||
db.query("""CREATE TABLE repository (
|
db.query("""CREATE TABLE repository (
|
||||||
handle CHARACTER(25),
|
handle CHARACTER(25),
|
||||||
gid CHARACTER(25),
|
gid CHARACTER(25),
|
||||||
@ -252,7 +276,7 @@ def makeDB(db):
|
|||||||
place CHARACTER(25),
|
place CHARACTER(25),
|
||||||
famc CHARACTER(25),
|
famc CHARACTER(25),
|
||||||
temple TEXT,
|
temple TEXT,
|
||||||
status TEXT,
|
status INTEGER,
|
||||||
private BOOLEAN);""")
|
private BOOLEAN);""")
|
||||||
|
|
||||||
db.query("""CREATE TABLE media_ref (
|
db.query("""CREATE TABLE media_ref (
|
||||||
@ -295,6 +319,12 @@ def makeDB(db):
|
|||||||
private BOOLEAN);
|
private BOOLEAN);
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
db.query("""CREATE TABLE datamap (
|
||||||
|
handle CHARACTER(25),
|
||||||
|
key_field TEXT,
|
||||||
|
value_field TXT);
|
||||||
|
""")
|
||||||
|
|
||||||
class Database(object):
|
class Database(object):
|
||||||
"""
|
"""
|
||||||
The db connection.
|
The db connection.
|
||||||
@ -740,6 +770,17 @@ def export_link(db, from_type, from_handle, to_type, to_handle):
|
|||||||
to_handle) values (?, ?, ?, ?)""",
|
to_handle) values (?, ?, ?, ?)""",
|
||||||
from_type, from_handle, to_type, to_handle)
|
from_type, from_handle, to_type, to_handle)
|
||||||
|
|
||||||
|
def export_datamap_dict(db, from_type, from_handle, datamap):
|
||||||
|
for key_field in datamap:
|
||||||
|
handle = create_id()
|
||||||
|
value_field = datamap[key_field]
|
||||||
|
db.query("""INSERT INTO datamap (
|
||||||
|
handle,
|
||||||
|
key_field,
|
||||||
|
value_field) values (?, ?, ?)""",
|
||||||
|
handle, key_field, value_field)
|
||||||
|
export_link(db, from_type, from_handle, "datamap", handle)
|
||||||
|
|
||||||
def export_address(db, from_type, from_handle, address):
|
def export_address(db, from_type, from_handle, address):
|
||||||
(private, asource_list, anote_list, date, location) = address
|
(private, asource_list, anote_list, date, location) = address
|
||||||
addr_handle = create_id()
|
addr_handle = create_id()
|
||||||
@ -776,10 +817,36 @@ def export_location(db, from_type, from_handle, location):
|
|||||||
# finally, link the parent to the address
|
# finally, link the parent to the address
|
||||||
export_link(db, from_type, from_handle, "location", handle)
|
export_link(db, from_type, from_handle, "location", handle)
|
||||||
|
|
||||||
|
def export_repository_ref_list(db, from_type, from_handle, reporef_list):
|
||||||
|
for repo in reporef_list:
|
||||||
|
(note_list,
|
||||||
|
ref,
|
||||||
|
call_number,
|
||||||
|
source_media_type,
|
||||||
|
private) = repo
|
||||||
|
handle = create_id()
|
||||||
|
db.query("""insert INTO repository_ref (
|
||||||
|
handle,
|
||||||
|
ref,
|
||||||
|
call_number,
|
||||||
|
source_media_type0,
|
||||||
|
source_media_type1,
|
||||||
|
private) VALUES (?,?,?,?,?,?);""",
|
||||||
|
handle,
|
||||||
|
ref,
|
||||||
|
call_number,
|
||||||
|
source_media_type[0],
|
||||||
|
source_media_type[1],
|
||||||
|
private)
|
||||||
|
export_list(db, "repository_ref", handle, "note", note_list)
|
||||||
|
# finally, link this to parent
|
||||||
|
export_link(db, from_type, from_handle, "repository_ref", handle)
|
||||||
|
|
||||||
def exportData(database, filename, option_box=None, callback=None):
|
def exportData(database, filename, option_box=None, callback=None):
|
||||||
if not callable(callback):
|
if not callable(callback):
|
||||||
callback = lambda (percent): None # dummy
|
callback = lambda (percent): None # dummy
|
||||||
|
|
||||||
|
start = time.time()
|
||||||
total = (len(database.note_map) +
|
total = (len(database.note_map) +
|
||||||
len(database.person_map) +
|
len(database.person_map) +
|
||||||
len(database.event_map) +
|
len(database.event_map) +
|
||||||
@ -952,14 +1019,8 @@ def exportData(database, filename, option_box=None, callback=None):
|
|||||||
marker[0], marker[1], private)
|
marker[0], marker[1], private)
|
||||||
export_list(db, "source", handle, "note", note_list)
|
export_list(db, "source", handle, "note", note_list)
|
||||||
export_media_ref_list(db, "source", handle, media_list)
|
export_media_ref_list(db, "source", handle, media_list)
|
||||||
# FIXME: reporef_list, datamap
|
export_datamap_dict(db, "source", handle, datamap)
|
||||||
#print "FIXME: reporef_list", reporef_list
|
export_repository_ref_list(db, "source", handle, reporef_list)
|
||||||
#print "FIXME: datamap", datamap
|
|
||||||
#FIXME: reporef_list []
|
|
||||||
#FIXME: datamap {}
|
|
||||||
#FIXME: reporef_list [([], u'b2cfa6e37654b308559', '', (2, u''), False)]
|
|
||||||
#FIXME: datamap {}
|
|
||||||
|
|
||||||
count += 1
|
count += 1
|
||||||
callback(100 * count/total)
|
callback(100 * count/total)
|
||||||
|
|
||||||
@ -996,12 +1057,18 @@ def exportData(database, filename, option_box=None, callback=None):
|
|||||||
count += 1
|
count += 1
|
||||||
callback(100 * count/total)
|
callback(100 * count/total)
|
||||||
|
|
||||||
|
total_time = time.time() - start
|
||||||
|
msg = ngettext('Export Complete: %d second','Export Complete: %d seconds', total_time ) % total_time
|
||||||
|
print msg
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Bookmarks
|
# Future ideas
|
||||||
# Header - researcher info
|
# Also include meta:
|
||||||
# Name formats
|
# Bookmarks
|
||||||
# Namemaps?
|
# Header - researcher info
|
||||||
|
# Name formats
|
||||||
|
# Namemaps?
|
||||||
|
# GRAMPS Version #, date, exporter
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
#
|
#
|
||||||
# $Id$
|
# $Id$
|
||||||
|
|
||||||
"Import from SQL Database"
|
"Import from SQLite Database"
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -29,7 +29,6 @@
|
|||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
from gettext import ngettext
|
from gettext import ngettext
|
||||||
import sqlite3 as sqlite
|
import sqlite3 as sqlite
|
||||||
import re
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
@ -47,15 +46,12 @@ log = logging.getLogger(".ImportSql")
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import gen.lib
|
import gen.lib
|
||||||
from QuestionDialog import ErrorDialog
|
from QuestionDialog import ErrorDialog
|
||||||
from DateHandler import parser as _dp
|
|
||||||
from gen.plug import PluginManager, ImportPlugin
|
from gen.plug import PluginManager, ImportPlugin
|
||||||
from Utils import gender as gender_map
|
|
||||||
from gui.utils import ProgressMeter
|
|
||||||
from Utils import create_id
|
from Utils import create_id
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Import function
|
# Import functions
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def lookup(handle, event_ref_list):
|
def lookup(handle, event_ref_list):
|
||||||
@ -75,7 +71,7 @@ def lookup(handle, event_ref_list):
|
|||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# SQL Reader
|
# SQLite DB Class
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
class Database(object):
|
class Database(object):
|
||||||
@ -109,6 +105,11 @@ class Database(object):
|
|||||||
self.cursor.close()
|
self.cursor.close()
|
||||||
self.db.close()
|
self.db.close()
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# SQL Reader
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
class SQLReader(object):
|
class SQLReader(object):
|
||||||
def __init__(self, db, filename, callback):
|
def __init__(self, db, filename, callback):
|
||||||
if not callable(callback):
|
if not callable(callback):
|
||||||
@ -174,8 +175,17 @@ class SQLReader(object):
|
|||||||
return retval
|
return retval
|
||||||
|
|
||||||
def get_datamap(self, sql, from_type, from_handle):
|
def get_datamap(self, sql, from_type, from_handle):
|
||||||
# FIXME:
|
handles = self.get_links(sql, from_type, from_handle, "datamap")
|
||||||
return {}
|
datamap = {}
|
||||||
|
for handle in handles:
|
||||||
|
row = sql.query("select * from datamap where handle = ?;",
|
||||||
|
handle)
|
||||||
|
if len(row) == 1:
|
||||||
|
(handle, key_field, value_field) = row[0]
|
||||||
|
datamap[key_field] = value_field
|
||||||
|
else:
|
||||||
|
print "ERROR: invalid datamap item '%s'" % handle
|
||||||
|
return datamap
|
||||||
|
|
||||||
def get_event_ref_list(self, sql, from_type, from_handle):
|
def get_event_ref_list(self, sql, from_type, from_handle):
|
||||||
results = self.get_links(sql, from_type, from_handle, "event_ref")
|
results = self.get_links(sql, from_type, from_handle, "event_ref")
|
||||||
@ -238,13 +248,13 @@ class SQLReader(object):
|
|||||||
def get_note_list(self, sql, from_type, from_handle):
|
def get_note_list(self, sql, from_type, from_handle):
|
||||||
return self.get_links(sql, from_type, from_handle, "note")
|
return self.get_links(sql, from_type, from_handle, "note")
|
||||||
|
|
||||||
def get_repository_list(self, sql, from_type, from_handle):
|
def get_repository_ref_list(self, sql, from_type, from_handle):
|
||||||
handles = self.get_links(sql, from_type, from_handle, "repository")
|
handles = self.get_links(sql, from_type, from_handle, "repository_ref")
|
||||||
results = []
|
results = []
|
||||||
for handle in handles:
|
for handle in handles:
|
||||||
results += sql.query("""select * from repository where handle = ?;""",
|
results += sql.query("""select * from repository_ref where handle = ?;""",
|
||||||
handle)
|
handle)
|
||||||
return [self.pack_repository(sql, result) for result in results]
|
return [self.pack_repository_ref(sql, result) for result in results]
|
||||||
|
|
||||||
def get_source_ref_list(self, sql, from_type, from_handle):
|
def get_source_ref_list(self, sql, from_type, from_handle):
|
||||||
handles = self.get_links(sql, from_type, from_handle, "source_ref")
|
handles = self.get_links(sql, from_type, from_handle, "source_ref")
|
||||||
@ -301,21 +311,19 @@ class SQLReader(object):
|
|||||||
role = (role0, role1, role2, role3)
|
role = (role0, role1, role2, role3)
|
||||||
return (private, source_list, note_list, attribute_list, ref, role)
|
return (private, source_list, note_list, attribute_list, ref, role)
|
||||||
|
|
||||||
def pack_repository(self, sql, data):
|
def pack_repository_ref(self, sql, data):
|
||||||
(handle,
|
(handle,
|
||||||
gid,
|
ref,
|
||||||
the_type0,
|
call_number,
|
||||||
the_type1,
|
source_media_type0,
|
||||||
name,
|
source_media_type1,
|
||||||
change,
|
|
||||||
marker0,
|
|
||||||
marker1,
|
|
||||||
private) = data
|
private) = data
|
||||||
note_list = self.get_note_list(sql, "repository", handle)
|
note_list = self.get_note_list(sql, "repository_ref", handle)
|
||||||
address_list = self.get_address_list(sql, "repository", handle, with_parish=False)
|
return (note_list,
|
||||||
urls = self.get_url_list(sql, "repository", handle)
|
ref,
|
||||||
return (handle, gid, (the_type0, the_type1), name, note_list,
|
call_number,
|
||||||
address_list, urls, change, (marker0, marker1), private)
|
(source_media_type0, source_media_type1),
|
||||||
|
private)
|
||||||
|
|
||||||
def pack_url(self, sql, data):
|
def pack_url(self, sql, data):
|
||||||
(handle,
|
(handle,
|
||||||
@ -361,7 +369,7 @@ class SQLReader(object):
|
|||||||
private) = data
|
private) = data
|
||||||
note_list = self.get_note_list(sql, "source", handle)
|
note_list = self.get_note_list(sql, "source", handle)
|
||||||
media_list = self.get_media_list(sql, "source", handle)
|
media_list = self.get_media_list(sql, "source", handle)
|
||||||
reporef_list = self.get_repository_list(sql, "source", handle)
|
reporef_list = self.get_repository_ref_list(sql, "source", handle)
|
||||||
datamap = {}
|
datamap = {}
|
||||||
return (handle, gid, title,
|
return (handle, gid, title,
|
||||||
author, pubinfo,
|
author, pubinfo,
|
||||||
@ -768,7 +776,7 @@ class SQLReader(object):
|
|||||||
note_list = self.get_note_list(sql, "source", handle)
|
note_list = self.get_note_list(sql, "source", handle)
|
||||||
media_list = self.get_media_list(sql, "source", handle)
|
media_list = self.get_media_list(sql, "source", handle)
|
||||||
datamap = self.get_datamap(sql, "source", handle)
|
datamap = self.get_datamap(sql, "source", handle)
|
||||||
reporef_list = self.get_repository_list(sql, "source", handle)
|
reporef_list = self.get_repository_ref_list(sql, "source", handle)
|
||||||
|
|
||||||
self.db.source_map[str(handle)] = (str(handle), gid, title,
|
self.db.source_map[str(handle)] = (str(handle), gid, title,
|
||||||
author, pubinfo,
|
author, pubinfo,
|
||||||
|
Loading…
Reference in New Issue
Block a user