From 13a018cb4c8747a51dd22dbed0300ec00e42405f Mon Sep 17 00:00:00 2001 From: Stephen Opal Date: Mon, 22 Jun 2009 14:16:47 +0000 Subject: [PATCH] Add a method which will "do the right thing" when the existence of the desired Crud table may be in question. --- lib/WebGUI/Crud.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/WebGUI/Crud.pm b/lib/WebGUI/Crud.pm index 94009180a..03ecf5017 100644 --- a/lib/WebGUI/Crud.pm +++ b/lib/WebGUI/Crud.pm @@ -192,6 +192,26 @@ sub create { #------------------------------------------------------------------- +=head2 crud_createOrUpdate ( session ) + +A detection class method used to affirm creation or update of the database table using the crud_definition(). Returns 1 on successful completion. + +=head3 session + +A reference to a WebGUI::Session. + +=cut + +sub crud_createOrUpdateTable { + my ( $class, $session ) = @_; + my $tableName = $class->crud_getTableName($session); + my $tableExists = $session->db->dbh->do("show tables like '$tableName'"); + + return ( $tableExists ne '0E0' ? $class->crud_updateTable($session) : $class->crud_createTable($session) ); +} + +#------------------------------------------------------------------- + =head2 crud_createTable ( session ) A management class method used to create the database table using the crud_definition(). Returns 1 on successful completion.