Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date object build error fixed #165

Merged
merged 2 commits into from Nov 20, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 24 additions & 16 deletions src/mysql_bindings_statement.cc
Expand Up @@ -673,22 +673,30 @@ Handle<Value> MysqlStatement::FetchAllSync(const Arguments& args) {
type == MYSQL_TYPE_DATETIME || // DATETIME type == MYSQL_TYPE_DATETIME || // DATETIME
type == MYSQL_TYPE_TIMESTAMP) { // TIMESTAMP type == MYSQL_TYPE_TIMESTAMP) { // TIMESTAMP
MYSQL_TIME ts = *((MYSQL_TIME *) ptr); MYSQL_TIME ts = *((MYSQL_TIME *) ptr);
DEBUG_PRINTF("Time: %04d-%02d-%02d %02d:%02d:%02d\n",
ts.year, ts.month, ts.day, DEBUG_PRINTF(
ts.hour, ts.minute, ts.second); "Time: %04d-%02d-%02d %02d:%02d:%02d\n",
time_t rawtime; ts.year, ts.month, ts.day,
struct tm * datetime; ts.hour, ts.minute, ts.second);
time(&rawtime);
datetime = localtime(&rawtime); char time_string[24];
datetime->tm_year = ts.year - 1900; sprintf(
datetime->tm_mon = ts.month - 1; time_string,
datetime->tm_mday = ts.day; "%04d-%02d-%02d %02d:%02d:%02d GMT",
datetime->tm_hour = ts.hour; ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
datetime->tm_min = ts.minute;
datetime->tm_sec = ts.second; // First step is to get a handle to the global object:
time_t timestamp = mktime(datetime); Local<v8::Object> globalObj = Context::GetCurrent()->Global();


js_field = Date::New(1000 * (double) timestamp); // Now we need to grab the Date constructor function:
Local<v8::Function> dateConstructor = Local<Function>::Cast(globalObj->Get(V8STR("Date")));

// Great. We can use this constructor function to allocate new Dates:
const int argc = 1;
Local<Value> argv[argc] = { V8STR(time_string) };

// Now we have our constructor, and our constructor args. Let's create the Date:
js_field = dateConstructor->NewInstance(argc, argv);
} else if (type == MYSQL_TYPE_SET) { // SET } else if (type == MYSQL_TYPE_SET) { // SET
// TODO(Sannis): Maybe memory leaks here // TODO(Sannis): Maybe memory leaks here
char *pch, *last, *field_value = (char *) ptr; char *pch, *last, *field_value = (char *) ptr;
Expand Down