sqlite2duckdb 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sqlite2duckdb-0.3.0/.gitignore +160 -0
- sqlite2duckdb-0.3.0/LICENSE +21 -0
- sqlite2duckdb-0.3.0/Makefile +12 -0
- sqlite2duckdb-0.3.0/PKG-INFO +74 -0
- sqlite2duckdb-0.3.0/README.md +59 -0
- sqlite2duckdb-0.3.0/pyproject.toml +29 -0
- sqlite2duckdb-0.3.0/requirements.txt +1 -0
- sqlite2duckdb-0.3.0/sqlite2duckdb/__init__.py +4 -0
- sqlite2duckdb-0.3.0/sqlite2duckdb/__main__.py +38 -0
- sqlite2duckdb-0.3.0/sqlite2duckdb/sqlite_to_duckdb.py +47 -0
- sqlite2duckdb-0.3.0/tests/test_convert.py +20 -0
- sqlite2duckdb-0.3.0/tests/utils.py +68 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# poetry
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
102
|
+
#poetry.lock
|
|
103
|
+
|
|
104
|
+
# pdm
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
106
|
+
#pdm.lock
|
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
108
|
+
# in version control.
|
|
109
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
110
|
+
.pdm.toml
|
|
111
|
+
|
|
112
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
113
|
+
__pypackages__/
|
|
114
|
+
|
|
115
|
+
# Celery stuff
|
|
116
|
+
celerybeat-schedule
|
|
117
|
+
celerybeat.pid
|
|
118
|
+
|
|
119
|
+
# SageMath parsed files
|
|
120
|
+
*.sage.py
|
|
121
|
+
|
|
122
|
+
# Environments
|
|
123
|
+
.env
|
|
124
|
+
.venv
|
|
125
|
+
env/
|
|
126
|
+
venv/
|
|
127
|
+
ENV/
|
|
128
|
+
env.bak/
|
|
129
|
+
venv.bak/
|
|
130
|
+
|
|
131
|
+
# Spyder project settings
|
|
132
|
+
.spyderproject
|
|
133
|
+
.spyproject
|
|
134
|
+
|
|
135
|
+
# Rope project settings
|
|
136
|
+
.ropeproject
|
|
137
|
+
|
|
138
|
+
# mkdocs documentation
|
|
139
|
+
/site
|
|
140
|
+
|
|
141
|
+
# mypy
|
|
142
|
+
.mypy_cache/
|
|
143
|
+
.dmypy.json
|
|
144
|
+
dmypy.json
|
|
145
|
+
|
|
146
|
+
# Pyre type checker
|
|
147
|
+
.pyre/
|
|
148
|
+
|
|
149
|
+
# pytype static type analyzer
|
|
150
|
+
.pytype/
|
|
151
|
+
|
|
152
|
+
# Cython debug symbols
|
|
153
|
+
cython_debug/
|
|
154
|
+
|
|
155
|
+
# PyCharm
|
|
156
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
157
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
158
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
159
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
160
|
+
#.idea/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 sacha schutz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: sqlite2duckdb
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: A tool to convert sqlite database to duckdb database
|
|
5
|
+
Project-URL: Homepage, https://github.com/dridk/sqlite2duckdb
|
|
6
|
+
Project-URL: Issues, https://github.com/dridk/sqlite2duckdb/issues
|
|
7
|
+
Author-email: Sacha Schutz <sacha.schutz@pm.me>
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: database,duckdb,olap,oltp,sqlite
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Requires-Dist: duckdb>=0.10.0
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# sqlite2duckdb
|
|
17
|
+
|
|
18
|
+

|
|
19
|
+

|
|
20
|
+
|
|
21
|
+
A tool for converting a [sqlite](https://www.sqlite.org/) database into a [duckdb](https://duckdb.org/) database
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## Description
|
|
25
|
+
|
|
26
|
+
Sqlite is an embedded online database designed for transactional reading and writing.
|
|
27
|
+
Duckdb is also an embedded database, but column-oriented, designed for analytical process with a very high reading efficiency.
|
|
28
|
+
See [https://towardsdatascience.com/forget-about-sqlite-use-duckdb-instead-and-thank-me-later-df76ee9bb777](https://towardsdatascience.com/forget-about-sqlite-use-duckdb-instead-and-thank-me-later-df76ee9bb777)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
pip install sqlite2duckdb
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
### As a command line
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
usage: sqlite2duckdb <sqlite_path> <duckdb_path>
|
|
44
|
+
|
|
45
|
+
Convert Sqlite database to Duckdb database
|
|
46
|
+
|
|
47
|
+
positional arguments:
|
|
48
|
+
sqlite_path sqlite file path
|
|
49
|
+
duckdb_path duckdb file path
|
|
50
|
+
|
|
51
|
+
options:
|
|
52
|
+
-h, --help show this help message and exit
|
|
53
|
+
-v, --version show program's version number and exit
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Examples
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
sqlite2duckdb source.db target.db
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### From python
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
|
|
68
|
+
from sqlite2duckdb import sqlite_to_duckdb
|
|
69
|
+
sqlite_to_duckdb("source.sqlite", "target.duckdb")
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# sqlite2duckdb
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
A tool for converting a [sqlite](https://www.sqlite.org/) database into a [duckdb](https://duckdb.org/) database
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Description
|
|
10
|
+
|
|
11
|
+
Sqlite is an embedded online database designed for transactional reading and writing.
|
|
12
|
+
Duckdb is also an embedded database, but column-oriented, designed for analytical process with a very high reading efficiency.
|
|
13
|
+
See [https://towardsdatascience.com/forget-about-sqlite-use-duckdb-instead-and-thank-me-later-df76ee9bb777](https://towardsdatascience.com/forget-about-sqlite-use-duckdb-instead-and-thank-me-later-df76ee9bb777)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
pip install sqlite2duckdb
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### As a command line
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
usage: sqlite2duckdb <sqlite_path> <duckdb_path>
|
|
29
|
+
|
|
30
|
+
Convert Sqlite database to Duckdb database
|
|
31
|
+
|
|
32
|
+
positional arguments:
|
|
33
|
+
sqlite_path sqlite file path
|
|
34
|
+
duckdb_path duckdb file path
|
|
35
|
+
|
|
36
|
+
options:
|
|
37
|
+
-h, --help show this help message and exit
|
|
38
|
+
-v, --version show program's version number and exit
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Examples
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
sqlite2duckdb source.db target.db
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### From python
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
|
|
53
|
+
from sqlite2duckdb import sqlite_to_duckdb
|
|
54
|
+
sqlite_to_duckdb("source.sqlite", "target.duckdb")
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling", "build", "twine"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
[project]
|
|
7
|
+
name = "sqlite2duckdb"
|
|
8
|
+
version = "0.3.0"
|
|
9
|
+
authors = [{name="Sacha Schutz", email="sacha.schutz@pm.me"}]
|
|
10
|
+
description = "A tool to convert sqlite database to duckdb database"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requres-python = ">=3.8"
|
|
13
|
+
keywords = ["sqlite", "duckdb", "database", "olap", "oltp"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
'duckdb >= 0.10.0'
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://github.com/dridk/sqlite2duckdb"
|
|
26
|
+
Issues = "https://github.com/dridk/sqlite2duckdb/issues"
|
|
27
|
+
|
|
28
|
+
[project.scripts]
|
|
29
|
+
sqlite2duckdb = "sqlite2duckdb.__main__:main_cli"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
duckdb
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import duckdb
|
|
2
|
+
import argparse
|
|
3
|
+
import os
|
|
4
|
+
from sqlite2duckdb import sqlite_to_duckdb, __VERSION__
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def main_cli():
|
|
8
|
+
parser = argparse.ArgumentParser(
|
|
9
|
+
description="Convert Sqlite database to Duckdb database",
|
|
10
|
+
usage="sqlite2duckdb <sqlite_path> <duckdb_path>",
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
parser.add_argument("sqlite_path", type=str, help="sqlite file path")
|
|
14
|
+
parser.add_argument("duckdb_path", type=str, help="duckdb file path")
|
|
15
|
+
parser.add_argument(
|
|
16
|
+
"-v", "--version", action="version", version=f"sqlite2duckdb {__VERSION__}"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
# Analyser les arguments
|
|
20
|
+
args = parser.parse_args()
|
|
21
|
+
|
|
22
|
+
if os.path.exists(args.duckdb_path):
|
|
23
|
+
delete_input = (
|
|
24
|
+
input(
|
|
25
|
+
f"{args.duckdb_path} already exists. do you want to delete this file ? (yes/no): "
|
|
26
|
+
)
|
|
27
|
+
.strip()
|
|
28
|
+
.lower()
|
|
29
|
+
)
|
|
30
|
+
if delete_input in ("yes", "y"):
|
|
31
|
+
os.remove(args.duckdb_path)
|
|
32
|
+
else:
|
|
33
|
+
exit(1)
|
|
34
|
+
sqlite_to_duckdb(args.sqlite_path, args.duckdb_path)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
if __name__ == "__main__":
|
|
38
|
+
main_cli()
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import duckdb
|
|
2
|
+
import os
|
|
3
|
+
import sqlite3
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def sqlite_to_duckdb(sqlite_db: str, duck_db: str):
|
|
8
|
+
print(f"Create {duck_db} databases")
|
|
9
|
+
|
|
10
|
+
if not os.path.exists(sqlite_db):
|
|
11
|
+
raise Exception(f"File {sqlite_db} doesn't exists")
|
|
12
|
+
|
|
13
|
+
# Remove target db if exists
|
|
14
|
+
if os.path.exists(duck_db):
|
|
15
|
+
raise Exception(f"Database {duck_db} already exists")
|
|
16
|
+
|
|
17
|
+
# Create databases
|
|
18
|
+
|
|
19
|
+
start_time = time.perf_counter()
|
|
20
|
+
conn = duckdb.connect(duck_db)
|
|
21
|
+
db_name = conn.sql("SELECT database_name FROM duckdb_databases").fetchone()[0]
|
|
22
|
+
|
|
23
|
+
## Install sqlite
|
|
24
|
+
conn.sql(
|
|
25
|
+
f"""
|
|
26
|
+
INSTALL sqlite;
|
|
27
|
+
LOAD sqlite;
|
|
28
|
+
ATTACH '{sqlite_db}' as __other;
|
|
29
|
+
"""
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
## Get sqlite Names
|
|
33
|
+
conn.sql("USE __other")
|
|
34
|
+
tables = [i[0] for i in conn.sql("SHOW tables").fetchall()]
|
|
35
|
+
print(f"{len(tables)} tables found(s)")
|
|
36
|
+
conn.sql(f"USE {db_name}")
|
|
37
|
+
|
|
38
|
+
# Create tables
|
|
39
|
+
for table in tables:
|
|
40
|
+
print(f"Create duckdb table {table}")
|
|
41
|
+
conn.sql(f"CREATE TABLE {table} AS select * FROM __other.{table}")
|
|
42
|
+
|
|
43
|
+
conn.sql(f"DETACH __other")
|
|
44
|
+
conn.close()
|
|
45
|
+
end_time = time.perf_counter()
|
|
46
|
+
execution_time = (end_time - start_time) * 1000
|
|
47
|
+
print(f"Done in {execution_time:.2f} ms !")
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import sqlite3
|
|
2
|
+
import duckdb
|
|
3
|
+
from tests import utils
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
from sqlite2duckdb.__main__ import sqlite_to_duckdb
|
|
7
|
+
|
|
8
|
+
def test_conversion():
|
|
9
|
+
|
|
10
|
+
duckdb_path = utils.generate_fake_duckdb()
|
|
11
|
+
sqlite_path = utils.generate_fake_sqlite()
|
|
12
|
+
|
|
13
|
+
sqlite_to_duckdb(sqlite_path, duckdb_path)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
|
|
2
|
+
import sqlite3
|
|
3
|
+
import random
|
|
4
|
+
import datetime
|
|
5
|
+
import tempfile
|
|
6
|
+
from faker import Faker
|
|
7
|
+
import os
|
|
8
|
+
|
|
9
|
+
def generate_fake_duckdb():
|
|
10
|
+
filename = tempfile.mkstemp(prefix="sqlite2duckdb_duck", suffix=".duckdb")[1]
|
|
11
|
+
if os.path.exists(filename):
|
|
12
|
+
os.remove(filename)
|
|
13
|
+
|
|
14
|
+
return filename
|
|
15
|
+
|
|
16
|
+
def generate_fake_sqlite():
|
|
17
|
+
|
|
18
|
+
temp_file_path = tempfile.mkstemp(prefix="sqlite2duckdb", suffix=".sqlite")[1]
|
|
19
|
+
print(f"Create temp sqlite db at {temp_file_path}")
|
|
20
|
+
fake = Faker()
|
|
21
|
+
|
|
22
|
+
conn = sqlite3.connect(temp_file_path)
|
|
23
|
+
cursor = conn.cursor()
|
|
24
|
+
|
|
25
|
+
# Create sqlite database
|
|
26
|
+
cursor.execute('''
|
|
27
|
+
CREATE TABLE IF NOT EXISTS data (
|
|
28
|
+
id INTEGER PRIMARY KEY,
|
|
29
|
+
integer_col INTEGER,
|
|
30
|
+
real_col REAL,
|
|
31
|
+
text_col TEXT,
|
|
32
|
+
boolean_col BOOLEAN,
|
|
33
|
+
date_col DATE,
|
|
34
|
+
time_col TIME,
|
|
35
|
+
datetime_col DATETIME,
|
|
36
|
+
blob_col BLOB,
|
|
37
|
+
numeric_col NUMERIC,
|
|
38
|
+
null_col NULL
|
|
39
|
+
)
|
|
40
|
+
''')
|
|
41
|
+
|
|
42
|
+
# Generate fake data
|
|
43
|
+
def generate_fake_data():
|
|
44
|
+
integer_col = random.randint(1, 1000)
|
|
45
|
+
real_col = random.uniform(1.0, 1000.0)
|
|
46
|
+
text_col = fake.text(max_nb_chars=20)
|
|
47
|
+
boolean_col = random.choice([True, False])
|
|
48
|
+
date_col = fake.date()
|
|
49
|
+
time_col = fake.date_time()
|
|
50
|
+
datetime_col = fake.date_time()
|
|
51
|
+
blob_col = fake.binary(length=10)
|
|
52
|
+
numeric_col = random.choice([integer_col, real_col])
|
|
53
|
+
null_col = None
|
|
54
|
+
return (integer_col, real_col, text_col, boolean_col, date_col, time_col, datetime_col, blob_col, numeric_col, null_col)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
for _ in range(1000):
|
|
58
|
+
|
|
59
|
+
cursor.execute('''
|
|
60
|
+
INSERT INTO data (integer_col, real_col, text_col, boolean_col, date_col, time_col, datetime_col, blob_col, numeric_col, null_col)
|
|
61
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
62
|
+
''', generate_fake_data())
|
|
63
|
+
|
|
64
|
+
# Sauvegarde (commit) des changements et fermeture de la connexion
|
|
65
|
+
conn.commit()
|
|
66
|
+
conn.close()
|
|
67
|
+
|
|
68
|
+
return temp_file_path
|