Skip to content

Conversation

@EmosewaMC
Copy link
Contributor

Fixes #13

The following main.cc code catches the CppSQLite3Exception since it now would inherit std::exception

#include "sqlite3.h"
#include "CppSQLite3.h"
#include <string>
#include <iomanip>
#include <iostream>
#include <cassert>

int main() {
	CppSQLite3DB conn;
	try {
		conn.open("test.sqlite");
		conn.compileStatement("select banana from 1");
	} catch (std::exception& e) {
		std::cout << e.what() << std::endl;
	}
	return 0;
}

add noexcept and change to return cstr
@EmosewaMC
Copy link
Contributor Author

EmosewaMC commented Apr 10, 2024

to be sure there were no added memory leaks, I used the following program which when run with valgrind has no memory leaks

#include "sqlite3.h"
#include "CppSQLite3.h"
#include <string>
#include <iomanip>
#include <iostream>
#include <cassert>

int main() {
	CppSQLite3DB conn;
	conn.open("test.sqlite");
	try {
		auto stmt = conn.compileStatement("select banana from ff");
		stmt.bind(1, "banana");
	} catch (std::exception& e) {
		std::cout << e.what() << std::endl;
	}
	return 0;
}

test.sqlite being opened and created with the following table

CREATE TABLE ff (banana text_4);

compiled with

g++ -std=c++11 -I. -c CppSQLite3.cpp
gcc -I. -c sqlite3.c
g++ -std=c++11 -I. main.cc CppSQLite3.o sqlite3.o

run with valgrind ./a.out

==24938== Memcheck, a memory error detector
==24938== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==24938== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==24938== Command: ./a.out
==24938==
==24938== error calling PR_SET_PTRACER, vgdb might block
SQLITE_RANGE[25]: Error binding string param
==24938== 
==24938== HEAP SUMMARY:
==24938==     in use at exit: 0 bytes in 0 blocks
==24938==   total heap usage: 78 allocs, 78 frees, 618,848 bytes allocated
==24938==
==24938== All heap blocks were freed -- no leaks are possible
==24938==
==24938== For lists of detected and suppressed errors, rerun with: -s
==24938== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

@mqudsi mqudsi merged commit ffd4a85 into neosmart:master Apr 16, 2024
@mqudsi
Copy link
Member

mqudsi commented Apr 16, 2024

Thanks, this looks good.

@EmosewaMC EmosewaMC deleted the 13 branch April 17, 2024 01:04
@mqudsi
Copy link
Member

mqudsi commented Jun 4, 2025

FYI I just pushed an update to correct the destructor signature to include override as a minor fix.

ef9a931

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CppSQLite3Exception does not inherit std::exception

2 participants