Fixed bug in querygenerator.

If sub block was just text, it was not considered valid by the upper
block.
This commit is contained in:
Robert Klotzner 2013-01-11 14:51:36 +01:00
parent 9b8ea8c5d1
commit 01b1b9df18
1 changed files with 11 additions and 10 deletions

View File

@ -254,7 +254,7 @@ string createQueryGenerator(string preSql) {
CreatedQuery createQuery(string queryString, StructT, Params...)(StructT data_, Params params) {
debug(queryGenerator) import std.stdio;
mixin(createQueryGenerator(queryString));
//writeln("Generated: ", createQueryGenerator(queryString));
debug(queryGenerator) writeln("Generated: ", createQueryGenerator(queryString));
return CreatedQuery(sql_, args_);
//return CreatedQuery.init;
}
@ -460,20 +460,20 @@ string preSqlParser(ref string data, int level=0) {
immutable buf="buf"~slevel;
immutable text="text"~slevel;
string upperBuf;
string upperValidCount;
string upperWasValid;
int dexprCount=0;
if(level>0) {
upperBuf="buf"~(to!string(level-1));
upperValidCount="validCount"~(to!string(level-1));
upperWasValid="wasValid"~(to!string(level-1));
}
else
upperBuf="sql_";
immutable validCount="validCount"~slevel;
immutable oldValidCount="oldValidCount"~slevel;
immutable wasValid="wasValid"~slevel;
immutable isFirst="isFirst"~to!string(level); // Defined in doVariableProcessing
out_cmd~="int "~validCount~"=-1;\n";
out_cmd~="int "~oldValidCount~"=-1;\n";
out_cmd~="int "~wasValid~";\n"; // Tri state: 0 not valid; -1 valid (was just text); >0 valid (contained valid D expressions)
out_cmd~="string "~text~";\n";
while(data.length) {
auto end=data.length;
@ -493,7 +493,6 @@ string preSqlParser(ref string data, int level=0) {
case '{' :
assert(data.length>2, "Expected some data after '{' at: "~data);
data=data[1..$];
out_cmd~=oldValidCount~"="~validCount~";\n";
out_cmd~="if("~validCount~"==0) {\n";
out_cmd~=buf~"="~buf~"[0..$-"~text~".length];\n}\n";
@ -502,8 +501,11 @@ string preSqlParser(ref string data, int level=0) {
assert(data[0]=='}', "Expected closing '}', got: "~data);
data=data[1..$];
out_cmd~="if("~oldValidCount~"=="~validCount~" && "~oldValidCount~">0) {\n";
out_cmd~="if("~wasValid~"==0 && "~validCount~">0) {\n"; // validCount has to be greater than 0 otherwise we have removed the data already. (See above)
out_cmd~=buf~"="~buf~"[0..$-"~text~".length];\n}\n";
out_cmd~="if("~wasValid~">0 || "~wasValid~"==0) {\n";
out_cmd~=validCount~"="~validCount~"==-1 ? "~wasValid~" : "~validCount~"+"~wasValid~";\n";
out_cmd~="}\n";
break;
case '}' :
goto finish;
@ -529,13 +531,12 @@ finish:
out_cmd~=isFirst~"=false;\n"; // No longer the first valid run, so separator should be inserted.
out_cmd~=upperBuf~"~="~buf~";\n}\n";
if(level>0) {
out_cmd~="if("~validCount~">=0) {\n";
out_cmd~=upperValidCount~"="~upperValidCount~">-1 ? "~upperValidCount~"+"~validCount~" : "~validCount~" ;\n}\n";
out_cmd~=upperWasValid~"="~validCount~";\n";
}
// End of loop:
out_cmd~="}\n";
if(level>0)
out_cmd~="if("~isFirst~") "~upperValidCount~"="~upperValidCount~"==-1 ? 0 : "~upperValidCount~";\n"; // In case loop wasn't executed a single time.
out_cmd~="if("~isFirst~") "~upperWasValid~"=0;\n"; // In case loop wasn't executed a single time.
out_cmd~="}\n";
return out_cmd;
}