Static analysis for strings

I want to implement static analysis to search strings and form a single total string from nested strings. This is necessary for analyzing sql queries in any program implemented on C++.

Code example:

std::string foo()
{
	return table1;
}

void bar()
{
	someClass->execute(std::string("select * from") + foo());
}

What I want to get:

std::string foo()
{
	return table1;
}

void bar()
{
	someClass->execute(std::string("select * from") + foo()); //example.cpp:8,24 contains the query "select * from table1;"
}

And I want to be able to further analyze the string “select * from table1;”, in order to output errors for the user, such as:

select * from table1;
______________^
The table is missing in the selected database in example.cpp:8,24

And display statistics:

table1 - 1 reference from example.cpp:8,24

I’m asking for your help with information about what guides can be used to understand how to implement static analysis, what tools can be used to implement it, similar projects for working with strings, and so on.

I would be extremely grateful for any information!