Skip to content

Commit c23f658

Browse files
committed
Sqlite update for GEPS 045
1 parent 50b3253 commit c23f658

File tree

2 files changed

+133
-57
lines changed

2 files changed

+133
-57
lines changed

Sqlite/ExportSql.py

+67-39
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#
5353
#------------------------------------------------------------------------
5454
from gramps.gen.utils.id import create_id
55+
from gramps.gen.lib import PlaceType
5556
from gramps.gen.const import GRAMPS_LOCALE as glocale
5657
from gramps.gui.plug.export import WriterOptionBox # don't remove, used!!!
5758
try:
@@ -186,13 +187,8 @@ def makeDB(db, callback):
186187
handle CHARACTER(25) PRIMARY KEY,
187188
gid CHARACTER(25),
188189
title TEXT,
189-
value TEXT,
190-
the_type0 INTEGER,
191-
the_type1 TEXT,
192-
code TEXT,
193190
long TEXT,
194191
lat TEXT,
195-
lang TEXT,
196192
change INTEGER,
197193
private BOOLEAN);""")
198194
count += 1
@@ -202,7 +198,9 @@ def makeDB(db, callback):
202198
db.query("""CREATE TABLE place_ref (
203199
handle CHARACTER(25) PRIMARY KEY,
204200
from_place_handle CHARACTER(25),
205-
to_place_handle CHARACTER(25));""")
201+
to_place_handle CHARACTER(25),
202+
h_type0 INTEGER,
203+
h_type1 TEXT);""")
206204
count += 1
207205
callback(100 * count / total)
208206

@@ -215,6 +213,25 @@ def makeDB(db, callback):
215213
count += 1
216214
callback(100 * count / total)
217215

216+
db.query("""drop table place_abbrev;""")
217+
db.query("""CREATE TABLE place_abbrev (
218+
handle CHARACTER(25) PRIMARY KEY,
219+
from_handle CHARACTER(25),
220+
value INTEGER,
221+
abbr_type0 INTEGER,
222+
abbr_type1 TEXT);""")
223+
count += 1
224+
callback(100 * count / total)
225+
226+
db.query("""drop table place_type;""")
227+
db.query("""CREATE TABLE place_type (
228+
handle CHARACTER(25) PRIMARY KEY,
229+
from_handle CHARACTER(25),
230+
value INTEGER,
231+
t_str TEXT);""")
232+
count += 1
233+
callback(100 * count / total)
234+
218235
db.query("""drop table event;""")
219236
db.query("""CREATE TABLE event (
220237
handle CHARACTER(25) PRIMARY KEY,
@@ -470,18 +487,41 @@ def close(self):
470487
self.db.close()
471488

472489

473-
def export_alt_place_name_list(db, handle, alt_place_name_list):
474-
for place_name in alt_place_name_list:
490+
def export_place_name_list(db, handle, place_name_list):
491+
for place_name in place_name_list:
475492
export_place_name(db, handle, place_name)
476493

477494

478495
def export_place_name(db, handle, place_name):
479496
# alt_place_name_list = [('Ohio', None, ''), ...] [(value, date, lang)...]
480-
(value, date, lang) = place_name
497+
(value, date, lang, abbr_list, citation_list) = place_name
481498
ref_handle = create_id()
482499
db.query("insert into place_name (handle, from_handle, value, lang)"
483500
" VALUES (?, ?, ?, ?);", ref_handle, handle, value, lang)
484501
export_date(db, "place_name", ref_handle, date)
502+
export_citation_list(db, "place_name", ref_handle, citation_list)
503+
export_place_abbr_list(db, ref_handle, abbr_list)
504+
505+
506+
def export_place_abbr_list(db, handle, place_abbr_list):
507+
for place_abbr in place_abbr_list:
508+
(value, a_type) = place_abbr
509+
ref_handle = create_id()
510+
db.query("insert into place_abbrev (handle, from_handle, value,"
511+
" abbr_type0, abbr_type1)"
512+
" VALUES (?, ?, ?, ?, ?);",
513+
ref_handle, handle, value, a_type[0], a_type[1])
514+
515+
516+
def export_place_type_list(db, handle, place_type_list):
517+
for place_type in place_type_list:
518+
(value, date, citation_list) = place_type
519+
ref_handle = create_id()
520+
db.query("insert into place_type (handle, from_handle, value, t_str)"
521+
" VALUES (?, ?, ?, ?);",
522+
ref_handle, handle, value, PlaceType(value).xml_str())
523+
export_date(db, "place_type", ref_handle, date)
524+
export_citation_list(db, "place_type", ref_handle, citation_list)
485525

486526

487527
def export_place_ref_list(db, handle, place_ref_list):
@@ -492,12 +532,14 @@ def export_place_ref_list(db, handle, place_ref_list):
492532

493533

494534
def export_place_ref(db, handle, place_ref):
495-
(to_place_handle, date) = place_ref
535+
(to_place_handle, date, citation_list, htype) = place_ref
496536
ref_handle = create_id()
497537
db.query("insert into place_ref"
498-
" (handle, from_place_handle, to_place_handle) VALUES (?, ?, ?);",
499-
ref_handle, handle, to_place_handle)
538+
" (handle, from_place_handle, to_place_handle, h_type0, h_type1)"
539+
" VALUES (?, ?, ?, ?, ?);",
540+
ref_handle, handle, to_place_handle, htype[0], htype[1])
500541
export_date(db, "place_ref", ref_handle, date)
542+
export_citation_list(db, "place_ref", ref_handle, citation_list)
501543

502544

503545
def export_location_list(db, from_type, from_handle, locations):
@@ -1159,56 +1201,42 @@ def exportData(database, filename, user, option_box):
11591201
continue
11601202
(handle, gid, title, long, lat,
11611203
place_ref_list,
1162-
place_name,
1163-
alt_place_name_list,
1164-
place_type,
1165-
code,
1204+
name_list,
1205+
type_list,
1206+
eventref_list,
11661207
alt_location_list,
11671208
urls,
11681209
media_list,
11691210
citation_list,
11701211
note_list,
1171-
change, tag_list, private) = place.serialize()
1172-
1173-
value, date, lang = place_name
1212+
change, tag_list, private,
1213+
attribute_list) = place.serialize()
11741214

11751215
db.query("""INSERT INTO place (
11761216
handle,
11771217
gid,
11781218
title,
1179-
value,
1180-
the_type0,
1181-
the_type1,
1182-
code,
11831219
long,
11841220
lat,
1185-
lang,
11861221
change,
1187-
private) values (?,?,?,?,?,?,?,?,?,?,?,?);""",
1188-
handle, gid, title, value,
1189-
place_type[0], place_type[1],
1190-
code,
1191-
long, lat,
1192-
lang,
1193-
change, private)
1222+
private) values (?,?,?,?,?,?,?);""",
1223+
handle, gid, title, long, lat, change, private)
11941224

1195-
export_date(db, "place", handle, date)
1225+
export_place_name_list(db, handle, name_list)
1226+
export_place_type_list(db, handle, type_list)
11961227
export_url_list(db, "place", handle, urls)
11971228
export_media_ref_list(db, "place", handle, media_list)
11981229
export_citation_list(db, "place", handle, citation_list)
11991230
export_list(db, "place", handle, "note", note_list)
12001231
export_list(db, "place", handle, "tag", tag_list)
1201-
1202-
#1. alt_place_name_list = [('Ohio', None, ''), ...]
1203-
# [(value, date, lang)...]
1204-
#2. place_ref_list = Enclosed by: [('4ECKQCWCLO5YIHXEXC', None)]
1205-
# [(handle, date)...]
1206-
1207-
export_alt_place_name_list(db, handle, alt_place_name_list)
12081232
export_place_ref_list(db, handle, place_ref_list)
1233+
export_attribute_list(db, "place", handle, attribute_list)
12091234

12101235
# But we need to link these:
12111236
export_location_list(db, "place_alt", handle, alt_location_list)
1237+
# Event Reference information
1238+
for event_ref in eventref_list:
1239+
export_event_ref(db, "place", handle, event_ref)
12121240

12131241
count += 1
12141242
callback(100 * count / total)

Sqlite/ImportSql.py

+66-18
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
#-------------------------------------------------------------------------
4646
from gramps.gen.lib import (Person, Family, Note, Media, Place, Citation,
4747
Source, Tag, Event, Repository, Name, Location,
48-
PlaceName)
48+
PlaceType)
49+
from gramps.gen.lib.placetype import DM_NAME
4950
from gramps.gen.db import DbTxn
5051
from gramps.gen.const import GRAMPS_LOCALE as glocale
5152
try:
@@ -187,7 +188,7 @@ def get_child_ref_list(self, sql, from_type, from_handle):
187188
(frel0, frel1), (mrel0, mrel1)))
188189
return retval
189190

190-
def get_datamap_list(self, sql, from_type, from_handle):
191+
def get_datamap_list(self, sql, _from_type, from_handle):
191192
datamap = []
192193
rows = sql.query("select * from datamap where from_handle = ?;",
193194
from_handle)
@@ -312,7 +313,7 @@ def pack_lds(self, sql, data):
312313
return (citation_list, note_list, date, type_, place,
313314
famc, temple, status, bool(private))
314315

315-
def pack_surnames(self, sql, data):
316+
def pack_surnames(self, _sql, data):
316317
(_handle,
317318
surname,
318319
prefix,
@@ -355,7 +356,7 @@ def pack_repository_ref(self, sql, data):
355356
(source_media_type0, source_media_type1),
356357
bool(private))
357358

358-
def pack_url(self, sql, data):
359+
def pack_url(self, _sql, data):
359360
(_handle,
360361
path,
361362
desc,
@@ -451,7 +452,7 @@ def pack_name(self, sql, data):
451452
(name_type0, name_type1),
452453
group_as, sort_as, display_as, call, nick, famnick)
453454

454-
def pack_location(self, sql, data, with_parish):
455+
def pack_location(self, _sql, data, with_parish):
455456
(_handle, street, locality, city, county, state, country, postal,
456457
phone, parish) = data
457458
if with_parish:
@@ -476,15 +477,27 @@ def get_place_from_handle(self, sql, ref_handle):
476477
" returned %d records." % (ref_handle, len(place_row)))
477478
return ''
478479

479-
def get_alt_place_name_list(self, sql, handle):
480+
def get_place_name_list(self, sql, handle):
480481
place_name_list = sql.query(
481482
"""select * from place_name where from_handle = ?;""", handle)
482483
retval = []
483484
for place_name_data in place_name_list:
484485
ref_handle, handle, value, lang = place_name_data
485486
date_handle = self.get_link(sql, "place_name", ref_handle, "date")
486487
date = self.get_date(sql, date_handle)
487-
retval.append((value, date, lang))
488+
abbr_list = self.get_place_abbr_list(sql, ref_handle)
489+
citation_list = self.get_citation_list(sql, "place_name",
490+
ref_handle)
491+
retval.append((value, date, lang, abbr_list, citation_list))
492+
return retval
493+
494+
def get_place_abbr_list(self, sql, handle):
495+
place_abbr_list = sql.query(
496+
"""select * from place_abbrev where from_handle = ?;""", handle)
497+
retval = []
498+
for place_abbr_data in place_abbr_list:
499+
_r_handle, handle, value, abbr_type0, abbr_type1 = place_abbr_data
500+
retval.append((value, (abbr_type0, abbr_type1)))
488501
return retval
489502

490503
def get_place_ref_list(self, sql, handle):
@@ -493,11 +506,45 @@ def get_place_ref_list(self, sql, handle):
493506
place_ref_list = sql.query(
494507
"""select * from place_ref where from_place_handle = ?;""", handle)
495508
retval = []
496-
for place_ref_data in place_ref_list:
497-
ref_handle, handle, to_place_handle = place_ref_data
509+
for ref_data in place_ref_list:
510+
ref_handle, handle, to_place_handle, h_type0, h_type1 = ref_data
498511
date_handle = self.get_link(sql, "place_ref", ref_handle, "date")
499512
date = self.get_date(sql, date_handle)
500-
retval.append((to_place_handle, date))
513+
citation_list = self.get_citation_list(sql, "place_ref",
514+
ref_handle)
515+
retval.append((to_place_handle, date, citation_list,
516+
(h_type0, h_type1)))
517+
return retval
518+
519+
def get_place_type_list(self, sql, handle):
520+
place_type_list = sql.query(
521+
"""select * from place_type where from_handle = ?;""",
522+
handle)
523+
retval = []
524+
for place_type_data in place_type_list:
525+
ref_handle, handle, type0, type1 = place_type_data
526+
date_handle = self.get_link(sql, "place_type", ref_handle, "date")
527+
date = self.get_date(sql, date_handle)
528+
citation_list = self.get_citation_list(sql, "place_type",
529+
ref_handle)
530+
retval.append((type0, date, citation_list))
531+
if type0 in PlaceType.DATAMAP:
532+
# if the number is already there, we are done
533+
continue
534+
if type0 < PlaceType.CUSTOM:
535+
# number is not definitive, check for already there by name
536+
for tup in PlaceType.DATAMAP.values():
537+
if type1.lower() == tup[DM_NAME].lower():
538+
break
539+
else:
540+
PlaceType.DATAMAP[type0] = (type1,
541+
PlaceType.G_PLACE, # groups
542+
True) # visible
543+
else:
544+
# not found, so store the new definition
545+
PlaceType.DATAMAP[type0] = (type1,
546+
PlaceType.G_PLACE, # groups
547+
True) # visible
501548
return retval
502549

503550
def get_main_location(self, sql, from_handle, with_parish):
@@ -784,8 +831,7 @@ def _process(self, count, total, sql):
784831
places = sql.query("""select * from place;""")
785832
for place in places:
786833
count += 1
787-
(handle, gid, title, value, the_type0, the_type1, code, long, lat,
788-
lang, change, private) = place
834+
(handle, gid, title, long, lat, change, private) = place
789835

790836
# We could look this up by "place_main", but we have the handle:
791837
#main_loc = self.get_main_location(sql, handle, with_parish=True)
@@ -796,14 +842,15 @@ def _process(self, count, total, sql):
796842
citation_list = self.get_citation_list(sql, "place", handle)
797843
note_list = self.get_note_list(sql, "place", handle)
798844
tags = self.get_links(sql, "place", handle, "tag")
799-
place_type = (the_type0, the_type1)
800-
alt_place_name_list = self.get_alt_place_name_list(sql, handle)
845+
place_type_list = self.get_place_type_list(sql, handle)
846+
place_name_list = self.get_place_name_list(sql, handle)
801847
place_ref_list = self.get_place_ref_list(sql, handle)
848+
eventref_list = self.get_event_ref_list(sql, "place", handle)
849+
attr_list = self.get_attribute_list(sql, "place", handle)
802850
data = (handle, gid, title, long, lat, place_ref_list,
803-
PlaceName(value=value, lang=lang).serialize(),
804-
alt_place_name_list, place_type, code, alt_loc_list,
805-
urls, media_list, citation_list, note_list,
806-
change, tags, private)
851+
place_name_list, place_type_list, eventref_list,
852+
alt_loc_list, urls, media_list, citation_list, note_list,
853+
change, tags, private, attr_list)
807854
g_plac = Place()
808855
g_plac.unserialize(data)
809856
self.db.commit_place(g_plac, self.trans)
@@ -900,3 +947,4 @@ def importData(db, filename, user):
900947
g = SQLReader(db, filename, user)
901948
g.process()
902949
g.cleanup()
950+
return _("Import finished...")

0 commit comments

Comments
 (0)