Hey i have a filename in this format RECORDddmmyyyy on my PC.

I want to include it into mysql table.I solve the problem of getting date but still have one issue,how to pass it to the database.

char filename ="RECORD"
i append later on the date to it as well as .txt and it works

I am using this statement to include it it works for one day only.
What should i write insted of RECORD14092010 so it can take "filename" instead of RECORD14092010
SQLWCHAR* SQL = L"LOAD DATA LOCAL INFILE 'C:/RECORD14092010.txt' INTO TABLE test FIELDS terminated by ','";

I think you just need to make the SQL string dynamic, is that your problem?

If so...

wchar_t SQL_Query_String[512];
int DateEncoded = 14092010;
swprintf(SQL_Query_String, 512, L"LOAD DATA LOCAL INFILE 'C:/RECORD%d.txt' INTO TABLE test FIELDS terminated by ','", DateEncoded);

Hey.cant i use the same syntax: SQLWCHAR* SQL=

And i want everyday to insert yesterday date not one specific date.

i have the code for yesterday no prob.

time_t now, yesterday;
char li[13];


time(&now);
yesterday = now-60*60*24;

strftime(li, 13, "%d%m%Y", localtime(&yesterday));

You replace DateEncoded with the result you just coded in your post.

And it seems like SQLWCHAR is actually a wchar_t, so it might be compatible. If it isn't, it shouldn't be hard to convert them.

I replaced it but not working. Check it for me:

SQLWCHAR* SQL = L"LOAD DATA LOCAL INFILE 'C:/RECORD%s.txt' INTO TABLE test FIELDS terminated by ','",li;

Or i have to use swprintf?

Yeah, use swprintf(). Your almost there.

How should i use it? should i include any library or smtg.
I would appreciate if you can provide me with the code.

Thank you

instead of SQL_query_string what should i write?

my variable currently is: SQLWCHAR outstr[1024];

i am writing:

swprintf(outstr, 1024, L"LOAD DATA LOCAL INFILE 'C:/RECORD%d.txt' INTO TABLE test FIELDS terminated by ','", li);

but not working

How should i use it? should i include any library or smtg.

And why haven't you searched google for "swprintf"? The answer to that is in literally a million places online.

I would appreciate if you can provide me with the code.

I think I provided you with enough code. This is your project after all. Ask me specific questions and I will answer them.

my variable currently is: SQLWCHAR outstr[1024];

Using my good friend google, I searched for "SQLWCHAR" and found out it is not a wchar_t, its instead an unsigned short. Since wchar_t can be 2 or 4 bytes depending on the implementation, It might be incompatible with swprintf(). Are you running linux or windows?

i am running windows

Then it should work, since SQLWCHAR is an unsigned short and so is wchar_t in your platform.

int li = 12345;

// This should work
SQLWCHAR outstr[1024]; 
swprintf(outstr, 1024, L"LOAD DATA LOCAL INFILE 'C:/RECORD%d.txt' INTO TABLE test FIELDS terminated by ','", li);

// It should be the same as this
wchar_t outstr[1024]; 
swprintf(outstr, 1024, L"LOAD DATA LOCAL INFILE 'C:/RECORD%d.txt' INTO TABLE test FIELDS terminated by ','", li);

If it still doesn't, show me the entire code you are using. Make sure its in [[b]CODE[/b]] tags.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.