Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/muntashirakon/python-sqlite

SQLite module for Python with PHP MySQLi like syntax
https://github.com/muntashirakon/python-sqlite

Last synced: 30 days ago
JSON representation

SQLite module for Python with PHP MySQLi like syntax

Awesome Lists containing this project

README

        

# Python SQLite
SQLite Database handler in Python with PHP-MySQLi like syntax

## Builds
master: [![Build Status](https://travis-ci.org/MuntashirAkon/Python-SQLite.svg?branch=master)](https://travis-ci.org/MuntashirAkon/Python-SQLite)
v0.1.0: [![Build Status](https://travis-ci.org/MuntashirAkon/Python-SQLite.svg?branch=v0.1.0)](https://travis-ci.org/MuntashirAkon/Python-SQLite)

## Documentation
Full documentation is covered in the [wiki page](https://github.com/MuntashirAkon/Python-SQLite/wiki).

Here's an quick example:
``` python
from sqlite import SQLite
# notice: you don't need to import sqlite3 module

sqlite = SQLite(":memory:")

# creates table
stmt = sqlite.prepare("""CREATE TABLE sample (
ID integer PRIMARY KEY AUTOINCREMENT NOT NULL,
Name text
)""")
stmt.execute()
stmt.close()

# insert a value
name = "Muntashir"
stmt = sqlite.prepare("INSERT INTO sample (Name) VALUES (?)")
stmt.bind_param('s', name)
stmt.execute()
if stmt.affected_rows > 0:
print(stmt.affected_rows, "rows added.")
print("inserted id:", stmt.insert_id)
stmt.close()

# select from table
stmt = sqlite.prepare("SELECT * FROM sample")
stmt.execute()
stmt.store_result()
if stmt.num_rows > 0:
name = []
id = []
print("ID\tName")
for i in range(0, stmt.num_rows):
stmt.bind_result(id, name)
stmt.fetch()
print("{}\t{}".format(id[0], name[0]))
stmt.close()
sqlite.close()
```

## Contribute
Contribution is always welcome. If you have better ideas or coding, you can always create a pull request or new issue.

## License
This project is licensed under [MIT License](https://github.com/MuntashirAkon/Python-SQLite/blob/master/LICENSE)