sqlparser/stats.cpp
// Log function call with all nested expressions
Log function call with all nested expressions
Log function call with all nested expressions
void Stats::LogFuncCall(Token *name, Token *end, std::string &cur_file)
{
	if(name == NULL || end == NULL)
		return;
	static bool first_call = true;
	const char *openMode = first_call ? "w" : "a";
	FILE *file = fopen(SQLEXEC_STAT_FILE, openMode);
	if(file != NULL)
	{
		fprintf(file, "%s,%d,%.*s,", cur_file.c_str(), name->line, (int)name->len, name->str);
		std::string src, src_meta;
		std::string tgt, tgt_meta;
		Token *cur = name;
		while(true)
		{
			const char *meta = GetMetaIdent(cur);
			if(!(cur->flags & TOKEN_INSERTED))
			{
				if(cur->str != NULL)
				{
					src.append(cur->str, cur->len);
					if(meta != NULL)
						src_meta.append(meta);
					else
						src_meta.append(cur->str, cur->len);
				}
				else
				if(cur->chr == '\r' || cur->chr == '\n' || cur->chr == '\t')
				{
					src += ' ';
					src_meta += ' ';
				}
				else
				{
					src += cur->chr;
					src_meta += cur->chr;
				}
			}
			if(!(cur->flags & TOKEN_REMOVED))
			{
				if(cur->t_str != NULL)
				{
					tgt.append(cur->t_str, cur->t_len);
					if(meta != NULL)
						tgt_meta.append(meta);
					else
						tgt_meta.append(cur->t_str, cur->t_len);
				}
				else
				if(cur->str != NULL)
				{
					tgt.append(cur->str, cur->len);
					if(meta != NULL)
						tgt_meta.append(meta);
					else
						tgt_meta.append(cur->str, cur->len);
				}
				else
				if(cur->chr == '\r' || cur->chr == '\n' || cur->chr == '\t')
				{
					tgt += ' ';
					tgt_meta += ' ';
				}
				else
				{
					tgt += cur->chr;
					tgt_meta += cur->chr;
				}
			}
			if(cur == end)
				break;
			cur = cur->next;
		}
		fprintf(file, "<sqlines>%s</sqlines>,<sqlines>%s</sqlines>,<sqlines>%s</sqlines>,<sqlines>%s</sqlines>", src.c_str(), tgt.c_str(), 
			src_meta.c_str(), tgt_meta.c_str());
		fprintf(file, "\n");
		fclose(file);
	}
	first_call = false;
}
void Stats :: LogFuncCall ( Token * name , Token * end , std :: string & cur_file ) { if ( name == NULL || end == NULL ) return ; static bool first_call = true ; const char * openMode = first_call ? " " : " " ; FILE * file = fopen ( SQLEXEC_STAT_FILE , openMode ) ; if ( file != NULL ) { fprintf ( file , " " , cur_file . c_str ( ) , name -> line , ( int ) name -> len , name -> str ) ; std :: string src , src_meta ; std :: string tgt , tgt_meta ; Token * cur = name ; while ( true ) { const char * meta = GetMetaIdent ( cur ) ; if ( ! ( cur -> flags & TOKEN_INSERTED ) ) { if ( cur -> str != NULL ) { src . append ( cur -> str , cur -> len ) ; if ( meta != NULL ) src_meta . append ( meta ) ; else src_meta . append ( cur -> str , cur -> len ) ; } else if ( cur -> chr == ' \r ' || cur -> chr == ' \n ' || cur -> chr == ' \t ' ) { src += ' ' ; src_meta += ' ' ; } else { src += cur -> chr ; src_meta += cur -> chr ; } } if ( ! ( cur -> flags & TOKEN_REMOVED ) ) { if ( cur -> t_str != NULL ) { tgt . append ( cur -> t_str , cur -> t_len ) ; if ( meta != NULL ) tgt_meta . append ( meta ) ; else tgt_meta . append ( cur -> t_str , cur -> t_len ) ; } else if ( cur -> str != NULL ) { tgt . append ( cur -> str , cur -> len ) ; if ( meta != NULL ) tgt_meta . append ( meta ) ; else tgt_meta . append ( cur -> str , cur -> len ) ; } else if ( cur -> chr == ' \r ' || cur -> chr == ' \n ' || cur -> chr == ' \t ' ) { tgt += ' ' ; tgt_meta += ' ' ; } else { tgt += cur -> chr ; tgt_meta += cur -> chr ; } } if ( cur == end ) break ; cur = cur -> next ; } fprintf ( file , " " , src . c_str ( ) , tgt . c_str ( ) , src_meta . c_str ( ) , tgt_meta . c_str ( ) ) ; fprintf ( file , " \n " ) ; fclose ( file ) ; } first_call = false ; }
Log function call with all nested expressions
Log function call with all nested expressions
// Line and source name // Build source and target strings // Source expression // Target expression