Skip to content

Commit

Permalink
re-debug xbrlDB xbrlSemanticDB with SQLite operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Herm Fischer authored and Herm Fischer committed Feb 12, 2015
1 parent acb2d58 commit 1dfd427
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
19 changes: 10 additions & 9 deletions arelle/plugin/xbrlDB/SqlDb.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,11 @@ def findstatements(start, end, laststatement):
statusMsg, sep, rest = sql.strip().partition('\n')
self.showStatus(statusMsg[0:50])
result = self.execute(sql, close=False, commit=False, fetch=False, action=action)
"""
if TRACESQLFILE:
with io.open(TRACESQLFILE, "a", encoding='utf-8') as fh:
fh.write("\n\n>>> ddl {0}: \n{1} \n\n>>> result: \n{2}\n"
.format(i, sql, result))
fh.write(sql)
"""
self.showStatus("")
self.conn.commit()
self.modelXbrl.profileStat(_("XbrlPublicDB: create tables"), time.time() - startedAt)
Expand Down Expand Up @@ -449,13 +447,16 @@ def tablesInDB(self):
}[self.product]))

def sequencesInDB(self):
return set(sequenceRow[0]
for sequenceRow in
self.execute({"postgres":"SELECT c.relname FROM pg_class c WHERE c.relkind = 'S';",
"mysql": "SHOW triggers;",
"mssql": "SELECT name FROM sys.triggers;",
"orcl": "SHOW trigger_name FROM user_triggers"
}[self.product]))
try:
return set(sequenceRow[0]
for sequenceRow in
self.execute({"postgres":"SELECT c.relname FROM pg_class c WHERE c.relkind = 'S';",
"mysql": "SHOW triggers;",
"mssql": "SELECT name FROM sys.triggers;",
"orcl": "SHOW trigger_name FROM user_triggers"\
}[self.product]))
except KeyError:
return set()

def columnTypeFunctions(self, table):
if table not in self.tableColTypes:
Expand Down
35 changes: 21 additions & 14 deletions arelle/plugin/xbrlDB/xbrlSemanticSQLiteDB.ddl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ CREATE TABLE filing (
entry_url TEXT
);
CREATE UNIQUE INDEX filing_index02 ON filing (filing_number);
CREATE INDEX filing_index03 ON filing (entity_id);

CREATE TABLE report (
report_id INTEGER PRIMARY KEY AUTOINCREMENT,
Expand Down Expand Up @@ -122,7 +123,8 @@ CREATE UNIQUE INDEX referenced_documents_index02 ON referenced_documents (objec
CREATE TABLE aspect (
aspect_id INTEGER PRIMARY KEY AUTOINCREMENT,
document_id INTEGER NOT NULL,
xml_id TEXT, -- xml id or element pointer (do we need this?)
xml_id TEXT,
xml_child_seq TEXT,
qname TEXT NOT NULL, -- clark notation qname (do we need this?)
name TEXT NOT NULL, -- local qname
datatype_id INTEGER,
Expand All @@ -134,15 +136,16 @@ CREATE TABLE aspect (
nillable BOOLEAN NOT NULL,
is_numeric BOOLEAN NOT NULL,
is_monetary BOOLEAN NOT NULL,
is_TEXT_block BOOLEAN NOT NULL
is_text_block BOOLEAN NOT NULL
);
CREATE INDEX aspect_index02 ON aspect (document_id);
CREATE INDEX aspect_index03 ON aspect (qname);

CREATE TABLE data_type (
data_type_id INTEGER PRIMARY KEY AUTOINCREMENT,
document_id INTEGER NOT NULL,
xml_id TEXT, -- xml id or element pointer (do we need this?)
xml_id TEXT,
xml_child_seq TEXT,
qname TEXT NOT NULL, -- clark notation qname (do we need this?)
name TEXT NOT NULL, -- local qname
base_type TEXT, -- xml base type if any
Expand All @@ -154,7 +157,8 @@ CREATE INDEX data_type_index03 ON data_type (qname);
CREATE TABLE role_type (
role_type_id INTEGER PRIMARY KEY AUTOINCREMENT,
document_id INTEGER NOT NULL,
xml_id TEXT, -- xml id or element pointer (do we need this?)
xml_id TEXT,
xml_child_seq TEXT,
role_uri TEXT NOT NULL,
definition TEXT
);
Expand All @@ -164,7 +168,8 @@ CREATE INDEX role_type_index03 ON role_type (role_uri);
CREATE TABLE arcrole_type (
arcrole_type_id INTEGER PRIMARY KEY AUTOINCREMENT,
document_id INTEGER NOT NULL,
xml_id TEXT, -- xml id or element pointer (do we need this?)
xml_id TEXT,
xml_child_seq TEXT,
arcrole_uri TEXT NOT NULL,
cycles_allowed TEXT NOT NULL,
definition TEXT
Expand All @@ -182,14 +187,14 @@ CREATE UNIQUE INDEX used_on_index02 ON used_on (object_id, aspect_id);
CREATE TABLE resource (
resource_id INTEGER PRIMARY KEY AUTOINCREMENT,
document_id INTEGER NOT NULL,
xml_id TEXT, -- xml id or element pointer (do we need this?)
xml_id TEXT,
xml_child_seq TEXT,
qname TEXT NOT NULL, -- clark notation qname (do we need this?)
role TEXT NOT NULL,
value TEXT,
xml_lang TEXT
);
CREATE INDEX resource_index02 ON resource (resource_id);
CREATE INDEX resource_index01 ON resource (resource_id);
CREATE INDEX resource_index02 ON resource (document_id, xml_child_seq);

CREATE TABLE relationship_set (
Expand Down Expand Up @@ -227,7 +232,7 @@ CREATE TABLE relationship (
CREATE INDEX relationship_index02 ON relationship (relationship_set_id);
CREATE INDEX relationship_index03 ON relationship (relationship_set_id, tree_depth);
CREATE INDEX relationship_index04 ON relationship (relationship_set_id, document_id, xml_child_seq);
CREATE INDEX relationship_index02 ON relationship (from_id);
CREATE INDEX relationship_index05 ON relationship (from_id);

CREATE TABLE data_point (
datapoint_id INTEGER PRIMARY KEY AUTOINCREMENT,
Expand All @@ -238,10 +243,10 @@ CREATE TABLE data_point (
source_line integer,
parent_datapoint_id INTEGER, -- id of tuple parent
aspect_id INTEGER NOT NULL,
conTEXT_xml_id TEXT, -- (do we need this?)
context_xml_id TEXT, -- (do we need this?)
entity_identifier_id INTEGER,
period_id INTEGER,
aspect_value_selections_id INTEGER,
aspect_value_selection_id INTEGER,
unit_id INTEGER,
is_nil BOOLEAN DEFAULT FALSE,
precision_value TEXT,
Expand All @@ -264,8 +269,8 @@ CREATE INDEX entity_identifier_index02 ON entity_identifier (report_id, identifi
CREATE TABLE period (
period_id INTEGER PRIMARY KEY AUTOINCREMENT,
report_id INTEGER,
start_date date,
end_date date,
start_date TEXT,
end_date TEXT,
is_instant BOOLEAN NOT NULL,
is_forever BOOLEAN NOT NULL
);
Expand All @@ -274,7 +279,8 @@ CREATE INDEX period_index02 ON period (report_id, start_date, end_date, is_inst
CREATE TABLE unit (
unit_id INTEGER PRIMARY KEY AUTOINCREMENT,
report_id INTEGER,
xml_id TEXT, -- xml id or element pointer (first if multiple)
xml_id TEXT,
xml_child_seq TEXT,
measures_hash TEXT
);
CREATE INDEX unit_index02 ON unit (report_id, measures_hash);
Expand Down Expand Up @@ -304,6 +310,7 @@ CREATE TABLE aspect_value_selection (
typed_value TEXT
);
CREATE INDEX aspect_value_selection_index01 ON aspect_value_selection (aspect_value_selection_id);
CREATE INDEX aspect_value_selection_index02 ON aspect_value_selection (aspect_id);

CREATE TABLE table_data_points(
report_id INTEGER,
Expand Down Expand Up @@ -14092,7 +14099,7 @@ INSERT INTO industry_level (industry_level_id, industry_classification, ancestor
(9323, 'NAICS', 1624, 54, 1, 1717, 54199, 4),
(9324, 'NAICS', 2037, 81, 1, 2082, 81221, 4),
(9325, 'NAICS', 2037, 81, 1, 2078, 812191, 5),
(9326, 'SIC', 3681, 4810, 3, 3682, 4812, 4;
(9326, 'SIC', 3681, 4810, 3, 3682, 4812, 4);

INSERT INTO industry_structure (industry_structure_id, industry_classification, depth, level_name) VALUES
(1, 'SIC', 1, 'Division'),
Expand Down

0 comments on commit 1dfd427

Please sign in to comment.