N
N
neosapient2016-03-22 20:05:04
MySQL
neosapient, 2016-03-22 20:05:04

Is there a SQL code generator in C++ for several databases at once (MySQL, SQLite, MS SQL)?

Hello.
I am looking for a C++ library that standardizes the generation of SQL queries and work with different databases: MySQL, SQLite, MS SQL.
Is there a ready solution to not write your bike?
Looking for something simple and lightweight. Or alternatively - popular in the community.
More about the problem:
Periodically, you have to write programs that work with different databases.
The programs are generally simple:
- check for the presence of a table and create a table,
- check for the presence of a field in the table, check the type of the field and edit the fields of the table
- perform SELECT, INSERT and UPDATE and read the result, or handle an error.
But as they say, the devil is in the details. For example, autoincrement can be written in different ways.
For MySQL, 'AUTO_INCREMENT' is used:

CREATE TABLE MyTable (
  id INT NOT NULL AUTO_INCREMENT,
  PRIMARY KEY(id)
);

For MS SQL, 'IDENTITY' is used:
CREATE TABLE MyTable  
(
 id INTEGER PRIMARY KEY IDENTITY(1,1)
);

For SQLite, 'AUTOINCREMENT' is used:
CREATE TABLE `MyTable` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL);

Another example: send an INSERT query, in which one of the fields must be inserted into the time in seconds from 1970.
MySQL: UNIX_TIMESTAMP()
SQLite: strftime('%s', 'now', 'localtime')
MS SQL: dbo.UNIX_TIMESTAMP(GETDATE())
About:
Windows, MS VS 2008, MySQL 5.6, MS SQL 2008, SQLite 3

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
iHateInventNames, 2016-03-22
@neosapient

Apparently you are talking about ORM

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question