A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C program to drop a database table dynamically in SQLite
Q:

C program to drop a database table dynamically in SQLite

0

C program to drop a database table dynamically in SQLite

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this program, we will drop a database table using source code dynamically in SQLite.

Program/Source Code:

The source code to drop a database table dynamically is given below. The given program is compiled and executed successfully on Ubuntu 20.04.

//C program to drop a database table dynamically in linux.

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

int main(void)
{
    sqlite3* db_ptr;
    char* errMesg = 0;

    int ret = 0;

    ret = sqlite3_open("MyDb.db", &db_ptr);

    if (ret != SQLITE_OK) {
        printf("Database opening error\n");
    }

    ret = sqlite3_exec(db_ptr, "drop table IF EXISTS Employee", 0, 0, &errMesg);

    if (ret != SQLITE_OK) {

        printf("Error in SQL statement: %s\n", errMesg);

        sqlite3_free(errMesg);
        sqlite3_close(db_ptr);

        return 1;
    }

    printf("Employee table dropped successfully\n");
    sqlite3_close(db_ptr);

    return 0;
}

Output:

$ ./drop_table 
Employee table dropped successfully
$ sqlite3 MyDb.db 
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
sqlite> .tables
sqlite> .exit

In the above program, we included the sqlite3.h header file to uses SQLite related functions. Here, we dropped the employee table in the "MyDb.db" database using sqlite3_exec() by passing a specified SQL statement.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now