CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
data_sources.sqlite_schema Class Reference
Inheritance diagram for data_sources.sqlite_schema:
data_sources.data_source data_sources.node

Public Member Functions

def __init__ (self, sqlite_file_name)
 
def data (self)
 
- Public Member Functions inherited from data_sources.data_source
def __init__ (self)
 
def __repr__ (self)
 
def get_data (self)
 
- Public Member Functions inherited from data_sources.node
def __init__ (self, data=None)
 
def __str__ (self)
 
def add_child (self, node_data)
 
def child (self, index)
 
def children (self)
 
def data (self)
 
def is_leaf (self)
 
def left_child (self)
 
def right_child (self)
 

Private Attributes

 _data
 
 _file_name
 

Detailed Description

Definition at line 80 of file data_sources.py.

Constructor & Destructor Documentation

def data_sources.sqlite_schema.__init__ (   self,
  sqlite_file_name 
)

Definition at line 82 of file data_sources.py.

82  def __init__(self, sqlite_file_name):
83  self._file_name = sqlite_file_name
84  # import sqlite3 and connect to the database file
85  import sqlite3
86  connection = sqlite3.connect(self._file_name)
87  cursor = connection.cursor()
88  if query_object == None:
89  # try to query the file to get table and column data
90  tables = cursor.execute("select name from sqlite_master where type = 'table'")
91 
92  # now build a mapping of tables to columns - with a dictionary
93  table_to_columns = {}
94  for table in tables.fetchall():
95  table_to_columns[table[0]] = []
96  # now query columns for this table
97  columns = cursor.execute("pragma table_info(%s)" % table[0])
98  for column in columns.fetchall():
99  table_to_columns[table[0]].append(str(column[1]))
100 
101  # now query with the mapping
102  table_to_data = {}
103  for table in table_to_columns:
104  # query with all columns
105  column_string = ",".join(table_to_columns[table])
106  sql_query = "select %s from %s" % (column_string, table)
107  results = cursor.execute(sql_query).fetchall()
108  for n in range(0, len(results)):
109  results[n] = dict(zip(table_to_columns[table], map(str, results[n])))
110  table_to_data[str(table)] = results
111  self._data = json_data_node.make(table_to_data)
112  else:
113  sql_query = query_object.to_sql()
114 
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def __init__(self, sqlite_file_name)
Definition: data_sources.py:82
#define str(s)

Member Function Documentation

def data_sources.sqlite_schema.data (   self)

Definition at line 115 of file data_sources.py.

References data_sources.node._data.

Referenced by data_sources.json_list.as_dicts(), data_sources.json_list.as_table(), data_sources.json_list.get_members(), and data_sources.json_list.last().

115  def data(self):
116  return self._data
117 
118 # used for chaining json-navigation methods
119 # when a method is called initially on the data, an object of this class is returned,
120 # then the methods on that object return an object of this class again.

Member Data Documentation

data_sources.sqlite_schema._data
private
data_sources.sqlite_schema._file_name
private

Definition at line 83 of file data_sources.py.