module sql.database_core2
¶
Short summary¶
module pyensae.sql.database_core2
Database
Classes¶
class |
truncated documentation |
---|---|
Complementary methods for class |
|
just to be meant to be caucht later by a unit test |
Methods¶
method |
truncated documentation |
---|---|
Checks the SQL connection. |
|
When values are inserted or updated, this method doubles |
|
Builds an |
|
Guesses the columns types from a file (the method assumes there is a header), The types are chosen in that order: … |
|
Processes a text line. |
|
Returns the python code associated to this database. |
|
Returns the list of tables, their columns, and their length. |
Documentation¶
- class pyensae.sql.database_core2.DatabaseCore2¶
Bases:
object
Complementary methods for class
Database
.- _check_connection()¶
Checks the SQL connection.
- _check_values(values)¶
When values are inserted or updated, this method doubles
"'"
it does not allow str values, only str.- Parameters:
values – dictionary
- Returns:
dictionary
- _get_insert_request(dico, table, exe=False, primarykey=None, cursor=None, skip_exception=False)¶
Builds an
INSERT SQL
request from a dictionary.- Parameters:
dico – dictionary
table – table name
exe – if True, execute the request, if False, do nothing except returning the request
primarykey – primary key column, if it exist
cursor – if None, creates a new one, otherwise use it
skip_exception – if True, log exception instead of raising one
- Returns:
str
- _guess_columns(file, format, columns_name=None, filter_case=None, header=True, encoding='utf-8')¶
Guesses the columns types from a file (the method assumes there is a header), The types are chosen in that order: int, float, str. It keeps the most frequent one with if there is not too many errors. The separator must be tabs (
\t
).- Parameters:
file – file name
format – format (only tsv)
columns_name – if None, the first line contains the columns, otherwise it is the columns name
filter_case – process every case information (used to replace space for example)
header – by default, the function is expected a header
encoding – encoding
- Returns:
columns, changes
- _process_text_line(line, columns, format, lower_case, num_line, fill_missing=0, filter_case=None, strict_separator=False)¶
Processes a text line.
- Parameters:
line – text line to process (or a list if it already splitted)
columns – columns definition
_append_table
format – only tsv for the moment
lower_case – put every str object in lower_case
num_line – line number
fill_missing – fill the missing values by a default value, at least not more than fill_missing values
filter_case – process every case information (used to replace space for example)
strict_separator – strict number of columns, it assumes there is no separator in the content of every column
- Returns:
a dictionary
- _split_expr = '\\r?\\t'¶
- get_python_code(varname='db')¶
Returns the python code associated to this database.
- Parameters:
varname – name of the variable
- Returns:
2-uple: simp, scode (import part, code part)
- summary(light=False)¶
Returns the list of tables, their columns, and their length.
- Parameters:
light – light version, no count, no first lines
- Returns:
a dictionary where the keys are (t,i), t is a table name, i is in [“columns”, “size”, “first_lines”], a str message