|
1 | 1 | {% macro sqlite__list_schemas(database) %} |
2 | | - {# no-op #} |
3 | | - {# see SQLiteAdapter.list_schemas() #} |
| 2 | + {% call statement('list_schemas', fetch_result=True) %} |
| 3 | + pragma database_list |
| 4 | + {% endcall %} |
| 5 | + {% set results = load_result('list_schemas').table %} |
| 6 | + {{ return(results.select(['name']).rename(column_names = {'name': 'schema'})) }} |
4 | 7 | {% endmacro %} |
5 | 8 |
|
6 | 9 | {% macro sqlite__create_schema(relation, auto_begin=False) %} |
|
34 | 37 | {%- endcall %} |
35 | 38 | {% endmacro %} |
36 | 39 |
|
37 | | -{% macro sqlite__check_schema_exists(database, schema) -%} |
38 | | - {# no-op #} |
39 | | - {# see SQLiteAdapter.check_schema_exists() #} |
| 40 | +{% macro sqlite__check_schema_exists(information_schema, schema) -%} |
| 41 | + {% if schema in list_schemas(database).columns[0].values() %} |
| 42 | + {% call statement('check_schema_exists', fetch_result=True) %} |
| 43 | + SELECT 1 as schema_exist |
| 44 | + {% endcall %} |
| 45 | + {{ return(load_result('check_schema_exists').table) }} |
| 46 | + {% else %} |
| 47 | + {% call statement('check_schema_exists', fetch_result=True) %} |
| 48 | + SELECT 0 as schema_exist |
| 49 | + {% endcall %} |
| 50 | + {{ return(load_result('check_schema_exists').table) }} |
| 51 | + {% endif %} |
40 | 52 | {% endmacro %} |
41 | 53 |
|
42 | 54 | {% macro sqlite__list_relations_without_caching(schema_relation) %} |
43 | | - {% call statement('list_relations_without_caching', fetch_result=True) %} |
44 | | - SELECT |
45 | | - '{{ schema_relation.database }}' as database |
46 | | - ,name |
47 | | - ,'{{ schema_relation.schema }}' AS schema |
48 | | - ,type as data_type |
49 | | - FROM |
50 | | - {{ schema_relation.schema }}.sqlite_master |
51 | | - WHERE |
52 | | - name NOT LIKE 'sqlite_%' |
53 | | - {% endcall %} |
54 | 55 |
|
55 | | - {{ return(load_result('list_relations_without_caching').table) }} |
| 56 | + {% set schemas = list_schemas(schema_relation.database).columns[0].values() %} |
| 57 | + |
| 58 | + {% if schema_relation.schema in schemas %} |
| 59 | + {% call statement('list_relations_without_caching', fetch_result=True) %} |
| 60 | + SELECT |
| 61 | + '{{ schema_relation.database }}' as database |
| 62 | + ,name |
| 63 | + ,'{{ schema_relation.schema }}' AS schema |
| 64 | + ,type as data_type |
| 65 | + FROM |
| 66 | + {{ schema_relation.schema }}.sqlite_master |
| 67 | + WHERE |
| 68 | + name NOT LIKE 'sqlite_%' |
| 69 | + {% endcall %} |
| 70 | + |
| 71 | + {{ return(load_result('list_relations_without_caching').table) }} |
| 72 | + {% else %} |
| 73 | + {% call statement('empty_table', fetch_result=True) %} |
| 74 | + SELECT null as database, null as name, null as schema, null as data_type WHERE 1=0 |
| 75 | + {% endcall %} |
| 76 | + |
| 77 | + {{ return(load_result('empty_table').table) }} |
| 78 | + {% endif %} |
56 | 79 | {% endmacro %} |
57 | 80 |
|
58 | 81 | {% macro sqlite__create_table_as(temporary, relation, sql) -%} |
|
0 commit comments