module sql.database_core2

Inheritance diagram of pyensae.sql.database_core2

Short summary

module pyensae.sql.database_core2

Database

source on GitHub

Classes

class

truncated documentation

DatabaseCore2

Complementary methods for class Database.

NoHeaderException

just to be meant to be caucht later by a unit test

Methods

method

truncated documentation

_check_connection

Checks the SQL connection.

_check_values

When values are inserted or updated, this method doubles "'" it does not allow str values, only str.

_get_insert_request

Builds an INSERT SQL request from a dictionary.

_guess_columns

Guesses the columns types from a file (the method assumes there is a header), The types are chosen in that order: …

_process_text_line

Processes a text line.

get_python_code

Returns the python code associated to this database.

summary

Returns the list of tables, their columns, and their length.

Documentation

Database

source on GitHub

class pyensae.sql.database_core2.DatabaseCore2[source]

Bases: object

Complementary methods for class Database.

source on GitHub

_check_connection()[source]

Checks the SQL connection.

source on GitHub

_check_values(values)[source]

When values are inserted or updated, this method doubles "'" it does not allow str values, only str.

Parameters

values – dictionary

Returns

dictionary

source on GitHub

_get_insert_request(dico, table, exe=False, primarykey=None, cursor=None, skip_exception=False)[source]

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

source on GitHub

_guess_columns(file, format, columns_name=None, filter_case=None, header=True, encoding='utf-8')[source]

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

source on GitHub

_process_text_line(line, columns, format, lower_case, num_line, fill_missing=0, filter_case=None, strict_separator=False)[source]

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

source on GitHub

_split_expr = '\\r?\\t'
get_python_code(varname='db')[source]

Returns the python code associated to this database.

Parameters

varname – name of the variable

Returns

2-uple: simp, scode (import part, code part)

source on GitHub

summary(light=False)[source]

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

source on GitHub

exception pyensae.sql.database_core2.NoHeaderException[source]

Bases: Exception

just to be meant to be caucht later by a unit test

source on GitHub