1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | function create_sa_functions() { global $wpdb; $wpdb->query( " IF NOT EXISTS( select * from sysprocedure where proc_name = 'MD5' ) THEN CREATE FUNCTION MD5( str varchar(255) ) RETURNS binary(32) BEGIN return HASH( str, 'MD5' ); END; END IF;"); $wpdb->query( " IF NOT EXISTS( select * from sysprocedure where proc_name = 'UNIX_TIMESTAMP' ) THEN CREATE FUNCTION UNIX_TIMESTAMP( dt datetime DEFAULT NULL ) RETURNS datetime BEGIN //Returns UTC data IF dt IS NULL THEN return DATEDIFF( second, '1979-01-01 00:00:00', CURRENT UTC TIMESTAMP ) ELSE return DATEDIFF( second, '1979-01-01 00:00:00', DATEADD( minute, -CONNECTION_PROPERTY('TimeZoneAdjustment'), dt) ) END IF END; END IF;"); $wpdb->query( " IF NOT EXISTS( select * from sysprocedure where proc_name = DEFAULTDAYOFMONTHDEFAULT ) THEN CREATE FUNCTION DAYOFMONTH( dt datetime ) RETURNS integer BEGIN return DAY( datetime ); END; END IF;"); $wpdb->query( "SET OPTION MAX_STATEMENT_COUNT=0;"); $wpdb->query( "SET OPTION MAX_CURSOR_COUNT=0;"); } |















1 response so far ↓
1 Bulding a Blog - Implementation Part I // Feb 26, 2009 at 11:35 am
[...] The create_sa_functions() procedure creates some user defined functions that do not exist as built-ins in SQL Anywhere. SQL Anywhere supports the functionality of these functions and so I simply added the functions as UDFs with the same name and mapped them to the SQL Anywhere functionality. Here is the source: create_sa_functions [...]
Leave a Comment
Note that all comments are currently being moderated until I have a better handle on spam, so your comment may not appear for a couple of hours