This patch is basically functional except for a problem with the event_timezones table import, which doesn't like negative values (e.g. -09:00) for the data type time. I'm not quite sure how to handle this yet; perhaps just add 24 hours to the value, but I'm not sure that's even correct.

Tested against Drupal 5.1, Postgres 8.1.8, and Event 5.x-2.x-dev (2007-04-20 release).

Comments

sammys’s picture

Assigned: HorsePunchKid » sammys

Hi,

Great work on the patch! Looks good other than the line below:

$ret[] = update_sql('CREATE INDEX {event}_timezone_index ON {event} (timezone)');

This needs to become the following in line with Drupal naming convention for indexes (index -> idx):

$ret[] = update_sql('CREATE INDEX {event}_timezone_idx ON {event} (timezone)');

I've eyeballed the code as i'm short of time and it looks solid.

Cheers,

Sammy Spets
Synerger
http://synerger.com

sammys’s picture

ooo and the offset might be better implemented as a decimal type rather than the time type. In PostgreSQL:

SELECT time '01:00' + interval '3.25 hours';
 ?column?
----------
 04:15:00
HorsePunchKid’s picture

StatusFileSize
new6.49 KB

This is still a work in progress, but here's a new patch against the current CVS head. New to this patch are support for Postgres installation (as opposed to just upgrading) and some Postgres fixes in event.module.

This patch still doesn't address the problem that Postgres's time data type doesn't support negative values. The interval data type looks much better suited, but I haven't tried it out yet.

HorsePunchKid’s picture

StatusFileSize
new7.66 KB

I switched over to using interval in Postgres, and it's working just about fine! The only problem I encountered is that if users don't have a timezone_id set, a join fails and no time shows up for the events. Going to the user edit page to set a timezone brings up another problem:

UPDATE d_users SET timezone = '58|-21600'...

That timezone won't fit into the varchar(8) that users.timezone is declared as. That said, the timezone_id still appeared to get set correctly.

Anyway, this patch is looking pretty good now, though I have still not tested it thoroughly.

HorsePunchKid’s picture

Status: Needs work » Needs review
StatusFileSize
new7.67 KB

With this patch, I can now fully uninstall and reinstall the module successfully. The only problems that came up this time around were again default zero timezones and problems changing the timezone as described above.

killes@www.drop.org’s picture

Status: Needs review » Active

Excellent, I've applied the patch.

There is another function which needs to be looked at: event_get_events. It is used by both the rss and the ical feeds and other stuff.

Also, the event_block_upcoming query.

HorsePunchKid’s picture

I looked through most of the queries to see if I could figure out what usually needs to get changed to make a MySQL-dialect query work with Postgres. Here's what I've observed so far:

INTERVAL %d SECOND          -> '%d seconds'
INTERVAL foo SECOND         -> foo
INTERVAL foo HOUR_SECOND    -> foo
%d SECOND                   -­> '%d seconds'
INTERVAL foo                -> foo
offset                      -> "offset"

How about a simple function, say _event_rewrite_sql($query)? It would encapsulate the translation logic, doing the switch($GLOBALS['db_type']) and regex work to massage the queries. Perhaps this would be better done in one of the db_ functions, but I presume it's better to get it working here first.

killes@www.drop.org’s picture

I'd prefer to not have a rewrite function, however we should document your findings in a code comment in event_get_events. There are only three places where we need to distinguish between mysql and pgsql.

HorsePunchKid’s picture

This approach seems to be more or less working for me. There's a problem with the calendar; it shows the events I add as starting on the 2nd of the month regardless of their actual start date. I think this is unrelated to my change, just because (using the Devel module) the queries seem to be returning the correct data.

The translation function I have so far looks like:

/**
 * Prepares a SQL query that uses time intervals for execution against
 * the MySQL or Postgres database. Queries are assumed to be MySQL-ready
 * and will be translated to Postgres dialect if necessary.
 *
 * @return string containing a query ready for execution
 */
function _event_rewrite_sql($query) {
  $translated=$query;

  if($GLOBALS['db_type']=="pgsql") {
    $translated=preg_replace('/(INTERVAL )?%d SECOND/', "'%d seconds'", $translated);
    $translated=preg_replace('/INTERVAL ([^ ]+)( (HOUR_)?SECOND)?/', '\1', $translated);
    $translated=preg_replace('/ offset /', ' "offset" ', $translated);
  }

  return $translated;
}
killes@www.drop.org’s picture

While it looks like it would work, I still don't like it. It is too much overhead for only three queries that need to be rewritten.

WRT to you 2nd of the month problem: Which calendar view are you using?

Also:
UPDATE d_users SET timezone = '58|-21600'...

This should not be happening. These two values need to go in two different columns.

HorsePunchKid’s picture

That's fine; I can whip up a patch that inlines that function and also drops a comment where you suggested. (It will probably be too verbose; please edit freely!)

The problem with the calendar appears in both the calendar block and at /event in the month, table, and list views at least. The upcoming events block shows the correct events but the parentheses that should contain the time-until are empty. I should reinstall the latest version before I scratch my head too much more about those problems.

I thought that user update query was odd, too. Whatever was going on is not going on now, and I was able to get my timezone and timezone_id set without going into the database.

HorsePunchKid’s picture

StatusFileSize
new8.66 KB

Here's a patch against the latest event-5.x-2.x-dev (08-May-2007 12:12).

This time around, I installed the module from scratch and used CCK instead of basicevent. The problems with labeling the title and body fields disappeared, of course, but the problem with the calendar page and block persists (events start to appear on the 2nd of the month, but the days on which they start and end are properly labeled with the time).

killes@www.drop.org’s picture

Status: Active » Fixed

patch applied. I am marking this fixed. yay!

Anonymous’s picture

Status: Fixed » Closed (fixed)