ToDelete() function in C++ is used to delete a row or tuple from the database table. There are different libraries available in C++ to work with databases, such as ODBC, SQLite, and MySQL.
In the above example, we used the ODBC package library to delete a row from the database table named TableName where the id is equal to 1. We initialized the environment, connection, and statement and executed the query using the SQLExecDirect() function. Finally, we freed up the memory using the SQLFreeHandle() function.
Package library used: ODBC
Example code using SQLite package library:
#include #include
int main() { sqlite3* db; char* errMsg;
// Open database int rc = sqlite3_open("DatabaseName.db", &db);
// Delete row from table rc = sqlite3_exec(db, "DELETE FROM TableName WHERE id = 1", 0, 0, &errMsg);
// Close database sqlite3_close(db);
return 0; }
In the above example, we used the SQLite package library to delete a row from the database table named TableName where the id is equal to 1. We opened the database using the sqlite3_open() function and executed the query using the sqlite3_exec() function. Finally, we closed the database using the sqlite3_close() function.
Package library used: SQLite
Example code using MySQL package library:
#include #include
int main() { MYSQL* conn; MYSQL_RES* res; MYSQL_ROW row;
// Delete row from table mysql_query(conn, "DELETE FROM TableName WHERE id = 1");
// Free results and close connection mysql_free_result(res); mysql_close(conn);
return 0; }
In the above example, we used the MySQL package library to delete a row from the database table named TableName where the id is equal to 1. We initialized the connection using the mysql_init() function and executed the query using the mysql_query() function. Finally, we freed up the memory using the mysql_free_result() function and closed the connection using the mysql_close() function.
Package library used: MySQL
C++ (Cpp) DB::del - 30 examples found. These are the top rated real world C++ (Cpp) examples of DB::del extracted from open source projects. You can rate examples to help us improve the quality of examples.