Search This Blog

Loading...

27 January 2012

Error C2001: newline in constant

In my current data migration project, where I have to migrate the data from VC++ Serialized data files to PostgreSQL database. I am writing a script in VC++, which will read all Serialized data files recursively in given root directory,  then fetch the data and insert it into Postgres database table. AS it’s my first VC++ program facing tons of error every day at the same time enjoying the learning curve :)

Here is the error I got today “Error C2001: newline in constant”, while trying to executing followinig code
----------------------------------------------------------------------------------
static CDatabase mydata;
if(!mydata.IsOpen()) {
     mydata.OpenEx("DSN=PGCSData",0);
}
CString strCmd;
strCmd.Format("INSERT INTO csetupdata (filename, version, load_main_id)
VALUES ('%s', %d, %d)",
currFlName, verson, GetData(LOAD_MAIN_ID));
mydata.ExecuteSQL( strCmd );
-----------------------------------------------------------------------------------

After some research I found the this error occur if  program contains a string literal that is incorrectly split over multiple lines (In our example string given in “strCmd.Format()”  is causing problem). Normally this is not allowed except that backslash character is included at the end of the first line. So ending the first line with backslash will solve this problem. So the correct Code is,

----------------------------------------------------------------------------------
static CDatabase mydata;
if(!mydata.IsOpen()) {
    mydata.OpenEx("DSN=PGCSData",0);
}
CString strCmd;
strCmd.Format("INSERT INTO csetupdata (filename, version, load_main_id)  \
VALUES ('%s', %d, %d)",
currFlName, verson, GetData(LOAD_MAIN_ID));
mydata.ExecuteSQL( strCmd );
----------------------------------------------------------------------------------

Hope this will be helpful to someone…

Query to find missing Id's in MySQL



SELECT a.id+1 AS start, MIN(b.id) - 1 AS end
FROM testtable AS a, testtable AS b
WHERE a.id < b.id
GROUP BY a.id
HAVING start < MIN(b.id)