user105127
user105127

Reputation: 25

exception thrown with sqlite select statement

I am willing to access a particular element present in the coloumn in my SQLite database so in order to achieve this I have used a select statement

char *query = {0};
            strcat(query, "SELECT ");//exception thrown here
            strcat(query, (char*)arr);//The value to be asscessed
            strcat(query, " FROM CARS");

but this is throwing an exception in ucrtbased.dll why?

update

I have referred this answer here and tried this,char* line1 = "SELECT "; char* line2 = (char*)arr; char* line3 = " FROM CARS"; size_t len1 = strlen(line1); size_t len2 = strlen(line2); size_t len3 = strlen(line3); char *query = (char*)malloc(len1 + len2 + len3 + 1); if (!query) abort(); memcpy(query, line1, len1); memcpy(query + len1, line2, len2); query[len1 + len2 + len3] = '\0';

but I found that I've done something wrong(because out put jumps to the else statement which means invalid sqlite statement) which I could not figure it out kindly help me.

I also referred this tutorial @ cplusplus.com but could not figure it out Thank you

Upvotes: 0

Views: 119

Answers (1)

Naveen
Naveen

Reputation: 73433

You have not allocated any memory to query and trying to copy some characters into it. You can create a variable on stack like char query[256] = {0}; if size is known. Else you can allocate memory dynamically using new[] and release it using delete[].

Upvotes: 1

Related Questions