Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

test0.c // g++ text.c -l sqlite3 #include #include int main(int argc, char* argv[]) { sqlite3 *db; char *zErrMsg = 0; int rc; rc = sqlite3_open(test.db,

image text in transcribed

test0.c

// g++ text.c -l sqlite3

#include #include

int main(int argc, char* argv[]) { sqlite3 *db; char *zErrMsg = 0; int rc;

rc = sqlite3_open("test.db", &db);

if( rc ){ fprintf(stderr, "Can't open database: %s ", sqlite3_errmsg(db)); }else{ fprintf(stderr, "Opened database successfully "); } sqlite3_close(db); }

test1.c

#include #include #include

static int callback(void *NotUsed, int argc, char **argv, char **azColName){ int i; for(i=0; i

int main(int argc, char* argv[]) { sqlite3 *db; char *zErrMsg = 0; int rc; char *sql;

/* Open database */ rc = sqlite3_open("test.db", &db); if( rc ){ fprintf(stderr, "Can't open database: %s ", sqlite3_errmsg(db)); exit(0); }else{ fprintf(stdout, "Opened database successfully "); }

/* Create SQL statement */ sql = "CREATE TABLE COMPANY(" \ "ID INT PRIMARY KEY NOT NULL," \ "NAME TEXT NOT NULL," \ "AGE INT NOT NULL," \ "ADDRESS CHAR(50)," \ "SALARY REAL );";

/* Execute SQL statement */ rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg); if( rc != SQLITE_OK ){ fprintf(stderr, "SQL error: %s ", zErrMsg); sqlite3_free(zErrMsg); }else{ fprintf(stdout, "Table created successfully "); } sqlite3_close(db); return 0; }

test2.c

#include #include #include

static int callback(void *NotUsed, int argc, char **argv, char **azColName){ int i; for(i=0; i

int main(int argc, char* argv[]) { sqlite3 *db; char *zErrMsg = 0; int rc; char *sql;

/* Open database */ rc = sqlite3_open("test.db", &db); if( rc ){ fprintf(stderr, "Can't open database: %s ", sqlite3_errmsg(db)); exit(0); }else{ fprintf(stderr, "Opened database successfully "); }

/* Create SQL statement */ sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " \ "VALUES (1, 'Paul', 32, 'California', 20000.00 ); " \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " \ "VALUES (2, 'Allen', 25, 'Texas', 15000.00 ); " \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \ "VALUES (3, 'Teddy', 23, 'Norway', 20000.00 );" \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \ "VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 );";

/* Execute SQL statement */ rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg); if( rc != SQLITE_OK ){ fprintf(stderr, "SQL error: %s ", zErrMsg); sqlite3_free(zErrMsg); }else{ fprintf(stdout, "Records created successfully "); } sqlite3_close(db); return 0; }

test3.c

#include #include #include

static int callback(void *data, int argc, char **argv, char **azColName){ int i; fprintf(stderr, "%s: ", (const char*)data); for(i=0; i

int main(int argc, char* argv[]) { sqlite3 *db; char *zErrMsg = 0; int rc; char *sql; const char* data = "Callback function called";

/* Open database */ rc = sqlite3_open("test.db", &db); if( rc ){ fprintf(stderr, "Can't open database: %s ", sqlite3_errmsg(db)); exit(0); }else{ fprintf(stderr, "Opened database successfully "); }

/* Create SQL statement */ sql = "SELECT * from COMPANY";

/* Execute SQL statement */ rc = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg); if( rc != SQLITE_OK ){ fprintf(stderr, "SQL error: %s ", zErrMsg); sqlite3_free(zErrMsg); }else{ fprintf(stdout, "Operation done successfully "); } sqlite3_close(db); return 0; }

test4.c

#include #include #include

static int callback(void *data, int argc, char **argv, char **azColName){ int i; fprintf(stderr, "%s: ", (const char*)data); for(i=0; i

int main(int argc, char* argv[]) { sqlite3 *db; char *zErrMsg = 0; int rc; char *sql; const char* data = "Callback function called";

/* Open database */ rc = sqlite3_open("test.db", &db); if( rc ){ fprintf(stderr, "Can't open database: %s ", sqlite3_errmsg(db)); exit(0); }else{ fprintf(stderr, "Opened database successfully "); }

/* Create merged SQL statement */ sql = "UPDATE COMPANY set SALARY = 25000.00 where ID=1; " \ "SELECT * from COMPANY";

/* Execute SQL statement */ rc = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg); if( rc != SQLITE_OK ){ fprintf(stderr, "SQL error: %s ", zErrMsg); sqlite3_free(zErrMsg); }else{ fprintf(stdout, "Operation done successfully "); } sqlite3_close(db); return 0; }

test5.c

#include #include #include

static int callback(void *data, int argc, char **argv, char **azColName){ int i; fprintf(stderr, "%s: ", (const char*)data); for(i=0; i

int main(int argc, char* argv[]) { sqlite3 *db; char *zErrMsg = 0; int rc; char *sql; const char* data = "Callback function called";

/* Open database */ rc = sqlite3_open("test.db", &db); if( rc ){ fprintf(stderr, "Can't open database: %s ", sqlite3_errmsg(db)); exit(0); }else{ fprintf(stderr, "Opened database successfully "); }

/* Create merged SQL statement */ sql = "DELETE from COMPANY where ID=2; " \ "SELECT * from COMPANY";

/* Execute SQL statement */ rc = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg); if( rc != SQLITE_OK ){ fprintf(stderr, "SQL error: %s ", zErrMsg); sqlite3_free(zErrMsg); }else{ fprintf(stdout, "Operation done successfully "); } sqlite3_close(db); return 0; }

PART1 C/C++ programming in unixlinux environment with sqlite3 Design and implement C/C++ program (a2partl.c or pp) to do the following tasks, to have a Makefle to compile the program, and to run the program to show each task done. You may use the sample programs (test0.c - test5.c) from Week05 Activity (sqlite3). Tasks/Steps to do Task #0. Design and implement C/C++ program (book0.c) to do the following items: (1) to create sqlite3 db file (emp) as you may use test0.c program as a basis of your program. Task#1. Design and implement C/C++ program (book 1.c) to define a table named book with following sal tatement. CREATE TABLE IF NOT EXISTS classics author varchar 128) DEFAULT NULL, title' yarchar 128) DEFAULT NULL, category varchar(16) DEFAULI NULL, year' char(4) DEFAULT NULL isbn char (13) NOT NULL DEFAULT ' PRIMARY KEY ('b) Task#2. Design and implement C/C++ program (book2.c) to insert the records into table book with the records as listed below INSERT INTO 'classics' ('author . ,title', 'category', 'year', 'abn.) VALUES ('Mark Twain', 'The Adventures of Tom Sawyer, 'Fiction', '1876', 9781598184891', ("Jane Austen', 'Pride and Prejudice', 'Fiction', '1811, 9780582506206', ('Charles Darwin', 'The Origin of Species, 'Non-Fiction','1856, 9780517123201') ('Charles Dickens', 'The Old Curiosity Shop', 'Fiction, '1841 9780099533474') ('William ShakespeareRomeo and Juliet', 'Eiction', 1594, 9780192814968, ('Herman Melville', "Moby Dick, "Fiction', '1851', '9780199535729'): Task#3. Design and implement C/C++program (book3.c) to select all the records from table book to be printed. Task#4 Design and implement C/C++ program (book4c) to update a record in table book so that the book's category will be changed from Fiction to Play for "Romeo and Juliet" and print the resulting content of the table. Task#5. Design and implement C/C++ program (book4c) to delete a record in table book so that "Moby Dick" will be deleted from the table, and to print the resulting content of the table

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions