In this program, we will create a database using the sqlite3_open() function dynamically in Linux.
Program/Source Code:
The source code to create a SQLite database dynamically is given below. The given program is compiled and executed successfully on Ubuntu 20.04.
//C program to create database dynamically in linux.
#include <sqlite3.h>
#include <stdio.h>
int main(void)
{
sqlite3* db_ptr;
int ret = 0;
ret = sqlite3_open("MyDb.db", &db_ptr);
if (ret == SQLITE_OK) {
printf("Database created successfully\n");
}
sqlite3_close(db_ptr);
return 0;
}
In the above program, we included the sqlite3.h header file to uses SQLITE related functions. Here, we created "MyDb.db" database using sqlite_open() function. The sqlite_open() function is used to open an existing database and if the database is not present then it will create a specified database automatically.
In this program, we will create a database using the sqlite3_open() function dynamically in Linux.
Program/Source Code:
The source code to create a SQLite database dynamically is given below. The given program is compiled and executed successfully on Ubuntu 20.04.
Output:
In the above program, we included the sqlite3.h header file to uses SQLITE related functions. Here, we created "MyDb.db" database using sqlite_open() function. The sqlite_open() function is used to open an existing database and if the database is not present then it will create a specified database automatically.
need an explanation for this answer? contact us directly to get an explanation for this answer