| 220 | |
| 221 | void registerDatabaseSQLite(DatabaseFactory & factory); |
| 222 | void registerDatabaseSQLite(DatabaseFactory & factory) |
| 223 | { |
| 224 | auto create_fn = [](const DatabaseFactory::Arguments & args) |
| 225 | { |
| 226 | auto * engine_define = args.create_query.storage; |
| 227 | const ASTFunction * engine = engine_define->engine; |
| 228 | |
| 229 | if (!engine->arguments || engine->arguments->children.size() != 1) |
| 230 | throw Exception(ErrorCodes::BAD_ARGUMENTS, "SQLite database requires 1 argument: database path"); |
| 231 | |
| 232 | const auto & arguments = engine->arguments->children; |
| 233 | |
| 234 | String database_path = safeGetLiteralValue<String>(arguments[0], "SQLite"); |
| 235 | |
| 236 | return std::make_shared<DatabaseSQLite>(args.context, engine_define, args.create_query.attach, database_path); |
| 237 | }; |
| 238 | factory.registerDatabase("SQLite", create_fn, { |
| 239 | .supports_arguments = true, |
| 240 | .is_external = true, |
| 241 | .source_access_type = AccessTypeObjects::Source::SQLITE, |
| 242 | }, Documentation{ |
| 243 | .description = R"DOCS_MD( |
| 244 | Allows to connect to [SQLite](https://www.sqlite.org/index.html) database and perform `INSERT` and `SELECT` queries to exchange data between ClickHouse and SQLite. |
| 245 | |
| 246 | ## Creating a database {#creating-a-database} |
| 247 | |
| 248 | ```sql |
| 249 | CREATE DATABASE sqlite_database |
| 250 | ENGINE = SQLite('db_path') |
| 251 | ``` |
| 252 | |
| 253 | **Engine Parameters** |
| 254 | |
| 255 | - `db_path` — Path to a file with SQLite database. |
| 256 | |
| 257 | ## Data types support {#data_types-support} |
| 258 | |
| 259 | The table below shows the default type mapping when ClickHouse automatically infers schema from SQLite: |
| 260 | |
| 261 | | SQLite | ClickHouse | |
| 262 | |---------------|---------------------------------------------------------| |
| 263 | | INTEGER | [Int32](../../sql-reference/data-types/int-uint.md) | |
| 264 | | REAL | [Float32](../../sql-reference/data-types/float.md) | |
| 265 | | TEXT | [String](../../sql-reference/data-types/string.md) | |
| 266 | | TEXT | [UUID](../../sql-reference/data-types/uuid.md) | |
| 267 | | BLOB | [String](../../sql-reference/data-types/string.md) | |
| 268 | |
| 269 | When you explicitly define a table with specific ClickHouse types using the [SQLite table engine](../../engines/table-engines/integrations/sqlite.md), the following ClickHouse types can be parsed from SQLite TEXT columns: |
| 270 | |
| 271 | - [Date](../../sql-reference/data-types/date.md), [Date32](../../sql-reference/data-types/date32.md) |
| 272 | - [DateTime](../../sql-reference/data-types/datetime.md), [DateTime64](../../sql-reference/data-types/datetime64.md) |
| 273 | - [UUID](../../sql-reference/data-types/uuid.md) |
| 274 | - [Enum8, Enum16](../../sql-reference/data-types/enum.md) |
| 275 | - [Decimal32, Decimal64, Decimal128, Decimal256](../../sql-reference/data-types/decimal.md) |
| 276 | - [FixedString](../../sql-reference/data-types/fixedstring.md) |
| 277 | - All integer types ([UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64](../../sql-reference/data-types/int-uint.md)) |
| 278 | - [Float32, Float64](../../sql-reference/data-types/float.md) |
| 279 |
no test coverage detected