From: Mike G. v. a. <we...@ma...> - 2009-01-25 15:40:08
|
Log Message: ----------- Changes to support archiving courses. Modified Files: -------------- webwork2/lib/WeBWorK/DB: Schema.pm webwork2/lib/WeBWorK/DB/Schema/NewSQL: Std.pm Revision Data ------------- Index: Schema.pm =================================================================== RCS file: /webwork/cvs/system/webwork2/lib/WeBWorK/DB/Schema.pm,v retrieving revision 1.12 retrieving revision 1.13 diff -Llib/WeBWorK/DB/Schema.pm -Llib/WeBWorK/DB/Schema.pm -u -r1.12 -r1.13 --- lib/WeBWorK/DB/Schema.pm +++ lib/WeBWorK/DB/Schema.pm @@ -54,6 +54,11 @@ 'WeBWorK::DB::Schema::Ex' => {}, 'WeBWorK::DB::Schema::Ex::RecordExists' => { isa => 'WeBWorK::DB::Schema::Ex', + description => "Record exists", + }, + 'WeBWorK::DB::Schema::Ex::TableMissing' => { + isa => 'WeBWorK::DB::Schema::Ex', + description =>"missing table", }, ); Index: Std.pm =================================================================== RCS file: /webwork/cvs/system/webwork2/lib/WeBWorK/DB/Schema/NewSQL/Std.pm,v retrieving revision 1.19 retrieving revision 1.20 diff -Llib/WeBWorK/DB/Schema/NewSQL/Std.pm -Llib/WeBWorK/DB/Schema/NewSQL/Std.pm -u -r1.19 -r1.20 --- lib/WeBWorK/DB/Schema/NewSQL/Std.pm +++ lib/WeBWorK/DB/Schema/NewSQL/Std.pm @@ -291,7 +291,8 @@ my $self = shift; my $field_name = shift; my $stmt = $self->_exists_field_stmt($field_name); - return $self->dbh->do($stmt); + my $result = $self->dbh->do($stmt); + return ($result eq "1") ? 1 : 0; # failed result is 0E0 } sub _exists_field_stmt { @@ -300,7 +301,21 @@ my $sql_table_name = $self->sql_table_name; return "Describe `$sql_table_name` `$field_name`"; } +#################################################### +# checking Tables +#################################################### +sub tableExists { + my $self = shift; + my $stmt = $self->_exists_table_stmt; + my $result = eval { $self->dbh->do($stmt); }; + ( caught WeBWorK::DB::Schema::Ex::TableMissing ) ? 0:1; +} +sub _exists_table_stmt { + my $self = shift; + my $sql_table_name = $self->sql_table_name; + return "Describe `$sql_table_name` "; +} ################################################################################ @@ -758,9 +773,10 @@ # maps error numbers to exception classes for MySQL our %MYSQL_ERROR_CODES = ( 1062 => 'WeBWorK::DB::Schema::Ex::RecordExists', + 1146 => 'WeBWorK::DB::Schema::Ex::TableMissing', ); -# turns MySQL error codes into excpetions -- WeBWorK::DB::Schema::Ex objects +# turns MySQL error codes into exceptions -- WeBWorK::DB::Schema::Ex objects # for known error types, and normal die STRING exceptions for unknown errors. # This is one method you'd want to override if you were writing a subclass for # another RDBMS. |