Skip to content

avraampiperidis/SqlStatementParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ code to determine the ranges of statements of a SQL string.

you can either copy the SqlStatementParser.cpp and SqlStatementParser.h files to use it directly.
Or build and add the exported dll into your project.
Notice. the dll file will work only for c++ projects as it's api methods using std direct types

use example
int main()
{
	std::vector<std::pair<size_t, size_t>> ranges;
	std::string sql = "select * from mytable; create table2(`id` not null /* ;ignored semicolon;*/ );\n \
		select * from table1 where t.prop like 'commnet;' and id = 3 #trailing; comment;;;;;";
	determineStatementRanges(sql.c_str(), sql.size(), ";", ranges, "\n");

	for (auto &range : ranges) {
		std::cout << '\n';
		std::cout << sql.substr(range.first, range.second);
		std::cout << '\n';
	}
	std::cin.ignore();
    return 0;
}