MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / registerStorageSQLite

Function registerStorageSQLite

src/Storages/StorageSQLite.cpp:211–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209
210void registerStorageSQLite(StorageFactory & factory);
211void registerStorageSQLite(StorageFactory & factory)
212{
213 factory.registerStorage("SQLite", [](const StorageFactory::Arguments & args) -> StoragePtr
214 {
215 ASTs & engine_args = args.engine_args;
216
217 if (engine_args.size() != 2)
218 throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "SQLite database requires 2 arguments: database path, table name");
219
220 for (auto & engine_arg : engine_args)
221 engine_arg = evaluateConstantExpressionOrIdentifierAsLiteral(engine_arg, args.getLocalContext());
222
223 const auto database_path = checkAndGetLiteralArgument<String>(engine_args[0], "database_path");
224 const auto table_name = checkAndGetLiteralArgument<String>(engine_args[1], "table_name");
225
226 auto sqlite_db = openSQLiteDB(database_path, args.getContext(), /* throw_on_error */ args.mode <= LoadingStrictnessLevel::CREATE);
227
228 return std::make_shared<StorageSQLite>(args.table_id, sqlite_db, database_path,
229 table_name, args.columns, args.constraints, args.comment, args.getContext());
230 },
231 {
232 .supports_schema_inference = true,
233 .source_access_type = AccessTypeObjects::Source::SQLITE,
234 },
235 Documentation{
236 .description = R"DOCS_MD(
237import CloudNotSupportedBadge from '@theme/badges/CloudNotSupportedBadge';
238
239# SQLite table engine
240
241<CloudNotSupportedBadge/>
242
243The engine allows to import and export data to SQLite and supports queries to SQLite tables directly from ClickHouse.
244
245## Creating a table {#creating-a-table}
246
247```sql
248 CREATE TABLE [IF NOT EXISTS] [db.]table_name
249 (
250 name1 [type1],
251 name2 [type2], ...
252 ) ENGINE = SQLite('db_path', 'table')
253```
254
255**Engine Parameters**
256
257- `db_path` — Path to SQLite file with a database.
258- `table` — Name of a table in the SQLite database.
259
260## Data types support {#data-types-support}
261
262When you explicitly specify ClickHouse column types in the table definition, the following ClickHouse types can be parsed from SQLite TEXT columns:
263
264- [Date](../../../sql-reference/data-types/date.md), [Date32](../../../sql-reference/data-types/date32.md)
265- [DateTime](../../../sql-reference/data-types/datetime.md), [DateTime64](../../../sql-reference/data-types/datetime64.md)
266- [UUID](../../../sql-reference/data-types/uuid.md)
267- [Enum8, Enum16](../../../sql-reference/data-types/enum.md)
268- [Decimal32, Decimal64, Decimal128, Decimal256](../../../sql-reference/data-types/decimal.md)

Callers 1

registerStoragesFunction · 0.85

Calls 7

openSQLiteDBFunction · 0.85
registerStorageMethod · 0.80
getLocalContextMethod · 0.80
ExceptionClass · 0.50
sizeMethod · 0.45
getContextMethod · 0.45

Tested by

no test coverage detected