Skip to content

CodebyCR/SQLite3_Interface

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple SQLite3 interface

Use a SQLite database for storing and retrieving data.

It's super easy to install:

Choose the command for your package manager:

brew install sqlite3
npm install sqlite3
sudo apt install sqlite3
sudo pacman -S sqlite3

... or download the binary from sqlite.org.

Usage

I administrate my SQLite databases favored with this VSCode extension: SQLite

Example

Create a database

    if(const auto create_query =
            "CREATE TABLE IF NOT EXISTS GRADES("
            "ID INTEGER PRIMARY KEY AUTOINCREMENT, "
            "NAME      TEXT NOT NULL, "
            "LNAME     TEXT NOT NULL, "
            "AGE       INT  NOT NULL, "
            "ADDRESS   CHAR(50), "
            "GRADE     CHAR(1) );";
            db.createTable(create_query)) {

        std::cerr << "Error in createTable function." << std::endl;
    }

Insert data

    if(const auto insert_query =
            "INSERT INTO GRADES (ID, NAME, LNAME, AGE, ADDRESS, GRADE) "
            "VALUES (2, 'Paul', 'Brown', 32, 'California', 1 );";
            db.addEntry(insert_query)) {
        
        std::cerr << "Error in addEntry function." << std::endl;
    }

Delete data

    if(const auto delete_query =
            "DELETE from GRADES where ID=2;";
            db.deleteEntry(delete_query)) {
        
        std::cerr << "Error in deleteEntry function." << std::endl;
    }

Select data

    if(const auto select_query =
            "Select * from GRADES";
            db.selectData(select_query)) {
    
        std::cerr << "Error in selectData function." << std::endl;
    }

Result of the example in main.cpp

Table created Successfully

After insert function:
2 Paul Brown 32 California 1 

After delete function:

Process finished with exit code 0

About

An example SQLite3 CMake module.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published