Skip to content

Commit

Permalink
Adding FROM_UNIXTIME() to SQLite3 #758
Browse files Browse the repository at this point in the history
  • Loading branch information
renecannao committed Oct 28, 2016
1 parent 451a3de commit b49966a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 216,195 deletions.
5 changes: 4 additions & 1 deletion deps/Makefile
Expand Up @@ -40,7 +40,10 @@ mariadb_client: mariadb-client-library/mariadb_client/include/my_config.h


sqlite3/sqlite3/sqlite3.o:
cd sqlite3/sqlite3 && ${CC} -O2 -c -o sqlite3.o sqlite3.c
cd sqlite3 && rm -rf sqlite-amalgamation-3150000
cd sqlite3 && tar -zxf sqlite-amalgamation-3150000.tar.gz
cd sqlite3/sqlite3 && patch sqlite3.c < ../from_unixtime.patch
cd sqlite3/sqlite3 && ${CC} -O2 -c -o sqlite3.o sqlite3.c -DSQLITE_ENABLE_MEMORY_MANAGEMENT

sqlite3: sqlite3/sqlite3/sqlite3.o

Expand Down
38 changes: 38 additions & 0 deletions deps/sqlite3/from_unixtime.patch
@@ -0,0 +1,38 @@
--- sqlite-amalgamation-3150000/sqlite3.c 2016-10-14 18:48:16.000000000 +0000
+++ /tmp/sqlite3.c 2016-10-28 00:22:06.993102669 +0000
@@ -19426,6 +19426,27 @@
}

/*
+** from_unixtime( TIMESTRING)
+**
+** Return YYYY-MM-DD HH:MM:SS
+*/
+static void from_unixtimeFunc(
+ sqlite3_context *context,
+ int argc,
+ sqlite3_value **argv
+){
+ DateTime x;
+ if( isDate(context, 1, argv, &x)==0 ){
+ parseModifier(context, (char*)"unixepoch", &x);
+ char zBuf[100];
+ computeYMD_HMS(&x);
+ sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d %02d:%02d:%02d",
+ x.Y, x.M, x.D, x.h, x.m, (int)(x.s));
+ sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
+ }
+}
+
+/*
** time( TIMESTRING, MOD, MOD, ...)
**
** Return HH:MM:SS
@@ -19715,6 +19736,7 @@
DFUNCTION(date, -1, 0, 0, dateFunc ),
DFUNCTION(time, -1, 0, 0, timeFunc ),
DFUNCTION(datetime, -1, 0, 0, datetimeFunc ),
+ DFUNCTION(from_unixtime, -1, 0, 0, from_unixtimeFunc ),
DFUNCTION(strftime, -1, 0, 0, strftimeFunc ),
DFUNCTION(current_time, 0, 0, 0, ctimeFunc ),
DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
Binary file added deps/sqlite3/sqlite-amalgamation-3150000.tar.gz
Binary file not shown.

0 comments on commit b49966a

Please sign in to comment.