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 81 of file data_sources.py.

Constructor & Destructor Documentation

def data_sources.sqlite_schema.__init__ (   self,
  sqlite_file_name 
)

Definition at line 83 of file data_sources.py.

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

Member Function Documentation

def data_sources.sqlite_schema.data (   self)

Definition at line 116 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().

116  def data(self):
117  return self._data
118 
119 # used for chaining json-navigation methods
120 # when a method is called initially on the data, an object of this class is returned,
121 # 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 84 of file data_sources.py.