This README provides guidance for setting up and working with the WinFormsDB project, which integrates SQLite3 with a C++/CLI WinForms application.
The following video demonstrates how to add the SQLite library to an existing WinForms project:
setup.mp4
The project consists of the following key files:
- Globals.h: Stores globally accessible data throughout the application
- Database.h: Contains declarations for CRUD functions (Create, Read, Update, Delete)
- Database.cpp: Implements the function bodies with database queries
- DatabaseMain.cpp: Handles SQLite3 database connection and query execution logic
- STR.h and Stringer.h: Helper files for string conversion between managed and unmanaged code
Ensure these files are included in your project:
- Header Files:
Globals.h
,Database.h
,STR.h
,Stringer.h
- Source Files:
sqlite3.c
,shell.c
,Database.cpp
,DatabaseMain.cpp
-
Copy Files to Project Directory:
- Copy all required header and source files to your project directory
- This ensures Visual Studio can properly reference these files
-
Add Files to Project:
- Add all header files to your project
- Add source files to a separate filter in your project
-
Configure C Files:
- Select
sqlite3.c
andshell.c
in the Solution Explorer - Right-click and select Properties
- Navigate to C/C++ → General
- Set "Common Language Runtime Support" to "No Common Language Runtime Support"
- Select
-
Configure Include Directories:
- Right-click on your project in Solution Explorer
- Select Properties
- Navigate to C/C++ → General
- In "Additional Include Directories," add the path to your SQLite3 folder
- Click OK/Apply to save changes
-
Database Connection Setup:
- In your main form's initialization code (before
Application::Run(% form)
), create a Database object on the heap - Store the pointer in
Globals::DB
- Example:
Globals::DB = new Database(); Application::Run(% form);
- In your main form's initialization code (before
Once properly set up, database functions can be accessed throughout the application:
Globals::DB->functionName(parameters);
- For schema creation and one-time database modifications, use DB Browser for SQLite
- Download link: https://sqlitebrowser.org/dl/
- This GUI tool simplifies database setup and query debugging
- The
execSQL
function returns data as a matrix of strings (Row × Column) - Use the provided string conversion functions to convert between managed and unmanaged strings
- A DEBUGGING flag in the Globals file can be enabled to:
- View return codes from database operations
- See queries before execution
Helper functions are provided for converting between System::String^
and std::string
:
- Use these functions when passing strings between managed UI code and unmanaged database code
- Set up the project structure as described above
- Create your database schema using DB Browser for SQLite
- Implement your database functions in Database.h and Database.cpp
- Access these functions from your forms using the global database pointer
When starting your own project, you may remove any sample code provided in the function implementations that aren't relevant to your features.
A video reference is provided to demonstrate adding the SQLite library to an existing WinForms project.