Пример #1
0
    def get_table(self, process_names: Callable[[str], str]
                  ) -> SQLTable:
        return SQLTable(
            name=process_names(self._table_name),
            fields=[field.process(process_names) for field in
                    self.get_fields()],
            indices=[index.process(process_names) for index in
                     self.get_indices()]

        )
Пример #2
0
 def setUp(self):
     print("SETUP MDB", unix_dialect.__dict__)
     self.field1 = SQLField("table",
                            "field1",
                            SQLTypes.BOOLEAN,
                            comment="comment")
     self.field2 = SQLField("table", "field2", SQLTypes.NUMERIC)
     self.index = SQLIndex("table", "field1", SQLIndexTypes.HASH)
     self.table = SQLTable("table", [self.field1, self.field2], [])
     self.query_provider = MariaDBQueryProvider()
Пример #3
0
 def test_copy_dialect(self):
     dialect = deepcopy(csv.excel)
     dialect.delimiter = '\t'
     dialect.doublequote = False
     dialect.escapechar = '\\'
     dialect.quotechar = "'"
     self.assertEqual(("COPY t FROM STDIN WITH (FORMAT CSV, HEADER TRUE, "
                       "ENCODING 'UTF_8', DELIMITER E'\t', ESCAPE E'\\\\', "
                       "QUOTE E'\\'')", ),
                      self.provider.copy_stream(SQLTable("t", [], []),
                                                "utf-8", dialect))
Пример #4
0
 def test_copy_stream(self):
     self.executor.copy_stream(SQLTable("table", [], []), BytesIO(b"data"),
                               "utf-8", unix_dialect)
     self.assertEqual([
         call.debug('%s (%s, %s)', 'INSERT INTO table VALUES ()', mock.ANY,
                    {})
     ], self.logger.mock_calls)
     self.assertEqual([
         call.cursor(),
         call.cursor().executemany('INSERT INTO table VALUES ()', mock.ANY)
     ], self.connection.mock_calls)
Пример #5
0
 def test_create_three(self):
     provider = PostgreSQLQueryProvider()
     self.assertEqual(
         ('CREATE TABLE t (\n'
          '    f1                    text,    -- comment1\n'
          '    field_with_long_name2 numeric,\n'
          '    f3                    text    -- comment2\n'
          ')', ),
         provider.create_table(
             SQLTable("t",
                      [self.sql_field1, self.sql_field2, self.sql_field3],
                      [])))
Пример #6
0
 def test_copy_stream(self):
     print(csv.unix_dialect.__dict__)
     self.executor.copy_stream(SQLTable("table", [], []), BytesIO(b"data"),
                               "utf-8", csv.unix_dialect)
     # self.assertEqual([call.debug("COPY table FROM STDIN WITH
     # (FORMAT CSV, "
     #                             "HEADER TRUE, ENCODING 'UTF_8')")],
     #                 self.logger.mock_calls)
     self.assertEqual([
         call.cursor(),
         call.cursor().execute(
             "COPY table FROM STDIN WITH (FORMAT CSV, "
             "HEADER TRUE, ENCODING 'UTF_8')",
             stream=mock.ANY)
     ], self.connection.mock_calls)
Пример #7
0
 def test_prepare_copy(self):
     self.table = SQLTable("table", [], [])
     self.assertEqual((), self.provider.prepare_copy(self.table))
Пример #8
0
 def test_create_two_fields_table(self):
     self.table = SQLTable("table", [self.field1, self.field2], [])
     self.assertEqual(('CREATE TABLE table (\n'
                       '    field1 boolean, -- comment\n'
                       '    field2 numeric\n'
                       ')', ), self.provider.create_table(self.table))
Пример #9
0
 def test_create_one_field_table(self):
     self.table = SQLTable("table", [self.field1], [])
     self.assertEqual(('CREATE TABLE table (\n'
                       '    field1 boolean -- comment\n'
                       ')', ), self.provider.create_table(self.table))
Пример #10
0
 def test_create_empty_table(self):
     self.table = SQLTable("table", [], [])
     self.assertEqual(('CREATE TABLE table ()', ),
                      self.provider.create_table(self.table))
Пример #11
0
 def test_drop_table(self):
     self.table = SQLTable("table", [], [])
     self.assertEqual(('DROP TABLE IF EXISTS table', ),
                      self.provider.drop_table(self.table))
Пример #12
0
 def test_create_empty(self):
     self.assertEqual(('CREATE TABLE t ()', ),
                      self.provider.create_table(SQLTable("t", [], [])))
Пример #13
0
 def test_create_one(self):
     self.assertEqual(
         ('CREATE TABLE t (\n'
          '    f1 text -- comment1\n'
          ')', ),
         self.provider.create_table(SQLTable("t", [self.sql_field1], [])))
Пример #14
0
 def test_finalize_copy(self):
     self.assertEqual(('ANALYZE t', ),
                      self.provider.finalize_copy(SQLTable("t", [], [])))
Пример #15
0
 def test_copy(self):
     self.assertEqual(("COPY t FROM STDIN WITH "
                       "(FORMAT CSV, HEADER TRUE, ENCODING 'UTF_8')", ),
                      self.provider.copy_stream(SQLTable("t", [], []),
                                                "utf-8", csv.excel))
Пример #16
0
 def test_prepare_copy(self):
     self.assertEqual(('TRUNCATE t', ),
                      self.provider.prepare_copy(SQLTable("t", [], [])))
Пример #17
0
 def test_insert_all(self):
     self.table = SQLTable("table", [self.field1, self.field2], [])
     self.assertEqual('INSERT INTO table VALUES (?, ?)',
                      self.provider.insert_all(self.table))
Пример #18
0
 def test_finalize_copy(self):
     self.table = SQLTable("table", [], [])
     self.assertEqual((), self.provider.finalize_copy(self.table))
Пример #19
0
 def test_create_other_index(self):
     self.table = SQLTable("other_table", [], [self.index])
     with self.assertRaises(AssertionError):
         self.query_provider.create_index(self.table, self.index)
Пример #20
0
def get_table(record_format: RecordFormat) -> SQLTable:
    fields = [
        SQLField(record_format.name, field, SQLTypes.TEXT, i)
        for i, field in enumerate(record_format.header)
    ]
    return SQLTable(record_format.name, fields, [])
Пример #21
0
 def test_drop(self):
     self.assertEqual(('DROP TABLE IF EXISTS t', ),
                      self.provider.drop_table(SQLTable("t", (), ())))
Пример #22
0
 def test_create_index(self):
     self.table = SQLTable("table", [], [self.index])
     self.assertEqual(
         ('DROP INDEX IF EXISTS field1_table_idx ON table',
          'CREATE INDEX field1_table_idx ON table(field1(255))'),
         self.query_provider.create_index(self.table, self.index))
Пример #23
0
 def test_one_with_index(self):
     sql_index = SQLIndex("t", "f", SQLIndexTypes.HASH)
     self.assertEqual(('DROP INDEX IF EXISTS f_t_idx',
                       'CREATE INDEX f_t_idx ON t USING hash(f)'),
                      self.provider.create_index(SQLTable("t", [], []),
                                                 sql_index))