Feeds:
Posts
Comments

I needed to get last month’s valid date range in php for running reports. A quick google search showed the top results for accomplishing this used for loops that subtracted/added days from now until casting as a date object returned false.

Needless to say, no way am I doing that. So below I have a code snippet that returns the valid start and end date of the previous month. This could be modified in a variety of ways to suit your needs. Needless to say I was disappointed that strtotime did not accept “First day of last month”.

// this returns a date string which I need, but removing the casting as a date
// returns a unix timestamp value more useful for calculations
$first_of_last_month = date('m/d/y',mktime(0,0,0,date('m')-1,1,date('y')));
$end_of_last_month = date('m/d/y',mktime(0,0,0,date('m'),0,date('y')));

// if run on 03/01/11
var_dump($first_of_last_month, $end_of_last_month);
// outputs
// string(8) "02/01/11"
// string(8) "02/28/11"

I was troubleshooting some long executing code when I discovered the difference between Execute on server command and it’s sibling checkbox in the method properties.

What you need to know:

Use checkbox if you care about the results of the executed code, you want the server to handle the processing and don’t care that the client waits for the response.

Use command to detach the wait from the client and process the code asynchronously.

I won’t go into much detail as it is well documented, but if you do some deep reading.

Tim Penner on “Command vs. Property”

One important difference is that the Execute on Server command always creates a new process, whether it is called in Client/Server mode or in single-user mode; the Execute on Server command still creates a new process.

In contrast the Execute on Server method attribute will not create a new process on the server, but will instead use a “twin” process of the client process that requested the execution. In Single-user mode, this method property has no affect and the method runs in the same process that requested its execution.

More Information
Execute on Server attribute:
http://www.4d.com/docs/CMU/CMU40945.HTM
Execute on Server command:
http://www.4d.com/docs/CMU/CMU00373.HTM
Stored Procedures:
http://www.4d.com/docs/CMU/CMU40975.HTM

My first attempt to mirror data from 4D to another database didn’t work. So, I’m taking another crack at it with lessons learned from my previous attempt.

My aim now is to make a component that will be transaction safe, and model itself after the 4D KB article published about Synchronization and Replication in v12 (4D partner login required). Since I am still using v11 and a v12 upgrade is not on the horizon, I am taking my own approach.

Component

Allow definition of multiple ‘mirror preferences’. Each of these linkages would define:

tables and fields to mirror
-> table pk field name
-> table last updated date/time field names
-> boolean field name to escape mirroring (so you can accept changes to the mirrored database and write them back without mirroring them out again)
interval to execute at
service to utilize (soap, file, sql, plugin)
last run date/time

@todo build synchronization of table/field names via alter table

Process

On the defined interval, or manually, the server process would spawn processes to look at target tables for updated/new records (making it transaction safe) and then of the records that were updated send over the target data.

Feel free to take it and run with it. Feedback and your thoughts welcome.

Say is there a market for companies that want to have their data available in a SQL database of repute?

More post to follow.

Design a site like this with WordPress.com
Get started