https://github.com/dustinkredmond/sqlitetocsv
Command line tool written in C language to export SQLite data as a CSV file.
https://github.com/dustinkredmond/sqlitetocsv
c csv sql sqlite-databases
Last synced: 7 months ago
JSON representation
Command line tool written in C language to export SQLite data as a CSV file.
- Host: GitHub
- URL: https://github.com/dustinkredmond/sqlitetocsv
- Owner: dustinkredmond
- Created: 2020-12-18T16:46:14.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-21T17:25:26.000Z (over 5 years ago)
- Last Synced: 2025-06-01T02:05:05.938Z (10 months ago)
- Topics: c, csv, sql, sqlite-databases
- Language: C
- Homepage:
- Size: 2.13 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## SQLiteToCSV
Provides the means to copy SQLite query results to a CSV file with your
choice of delimiter. I originally wrote this program in about 30 lines of Python code, but found
that for extremely large SQLite databases I wasn't getting the performance that I needed. Hence this...
---
### Building
Ensure that you have a `C` compiler installed (GCC preferred). Next,
install the SQLite library. If using the `apt` package manager, this is
accomplished by the following command, some Linux distros may already include this.
```
sudo apt install libsqlite3-dev
```
Next, clone the project from GitHub and change directory.
```
git clone https://github.com/dustinkredmond/SQLiteToCSV && cd SQLiteToCSV
```
To compile from source, run the following (requires CMake and Make)
```
cmake . && make
```
An executable will be generated, run it as so.
```
./SQLiteToCsv
```
---
### Command line options
- -db - Path to SQLite database
- -out - Path to export CSV file
- -delimiter - Delimiter to use in CSV file (optional) defaults to comma if not provided
- -sql - SQL query to retrieve from database
- -prompt - Prompt the user to continue (doesn't by default)
- -help - Print information seen here
---
### Usage
Let's say we have a database called `Test.db` in the current working directory.
`Test.db` has a table `EMPLOYEE`. If we wanted a subset of the records in this
table we could make a call to SQLiteToCSV like below.
```shell
./SQLiteToCSV -db ./Test.db -out ./Test.csv -sql "SELECT * FROM EMPLOYEE WHERE DEPARTMENT_ID = 15"
```
This would in turn run the query against the SQLite database, and pop out a `Test.csv` file
in the directory specified.
---
### Not supported
BLOBs or other binary objects. Instead, the string '<BLOB format not supported>' will be written.