Loading, please wait...

A to Z Full Forms and Acronyms

C program to get SQLite version using 'SELECT' statement in Linux | C programming

Jun 24, 2021 C programming, 349 Views
C program to get SQLite version using 'SELECT' statement in Linux | C programming

C program to get SQLite version using 'SELECT' statement in Linux | C programming

Prerequisites:

sudo apt install sqlite3
sudo apt install gcc
sudo apt install libsqlite3-dev

In this program, we will get the SQLite version using the "SELECT" statement and then print the SQLITE version on the console screen.

#include <sqlite3.h>
#include <stdio.h>

int main(void)
{
    sqlite3* db_ptr;
    sqlite3_stmt* stmt;

    int ret = 0;

    ret = sqlite3_open(":memory:", &db_ptr);

    if (ret != SQLITE_OK) {
        printf("\nDatabase opening error");
        sqlite3_close(db_ptr);
        return 1;
    }

    ret = sqlite3_prepare_v2(db_ptr, "SELECT SQLITE_VERSION()", -1, &stmt, 0);

    if (ret != SQLITE_OK) {
        printf("\nUnable to fetch data");
        sqlite3_close(db_ptr);
        return 1;
    }

    ret = sqlite3_step(stmt);

    if (ret == SQLITE_ROW)
        printf("SQLITE Version: %s\n", sqlite3_column_text(stmt, 0));

    sqlite3_finalize(stmt);
    sqlite3_close(db_ptr);

    return 0;
}
A to Z Full Forms and Acronyms

Related Article