Bug 7902

Summary: Adding Function to Check for Existence of Tables
Product: Koha Reporter: Chris Nighswonger <cnighswonger>
Component: DatabaseAssignee: Chris Nighswonger <cnighswonger>
Status: CLOSED FIXED QA Contact: Ian Walls <koha.sekjal>
Severity: enhancement    
Priority: P5 - low CC: jonathan.druart, paul.poulain
Version: 3.8   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24994
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Attachments: Patch to add feature
Bug 7902 - Adding Function to Check for Existence of Tables

Description Chris Nighswonger 2012-04-05 13:39:01 UTC
This patch adds a function TableExists which checks for the existence of a given table and returns 1 or 0 accordingly. This allows us to check for the existence of a given table when doing operations on tables which may not exist in a given database which, in turn, will reduce the number of red errors which show up after an upgrade.

An example of its use is included in this patch.
Comment 1 Chris Nighswonger 2012-04-05 13:41:07 UTC Comment hidden (obsolete)
Comment 2 Jonathan Druart 2012-04-05 13:54:19 UTC
QA Comment, 

Why don't you simply use the following syntax:
  DROP TABLE IF NOT EXISTS $tablename

It is supported by mysql and postgresql

http://dev.mysql.com/doc/refman/5.1/en/drop-table.html
http://www.postgresql.org/docs/8.2/static/sql-droptable.html
Comment 3 Chris Nighswonger 2012-04-05 13:56:52 UTC
(In reply to comment #2)
> QA Comment, 
> 
> Why don't you simply use the following syntax:
>   DROP TABLE IF NOT EXISTS $tablename
> 
> It is supported by mysql and postgresql
> 
> http://dev.mysql.com/doc/refman/5.1/en/drop-table.html
> http://www.postgresql.org/docs/8.2/static/sql-droptable.html

The included syntax is truly DB agnostic, whereas some DBs may implement EXISTS differently.
Comment 4 Jared Camins-Esakov 2012-04-05 14:07:12 UTC
Created attachment 8921 [details] [review]
Bug 7902 - Adding Function to Check for Existence of Tables

This patch adds a function TableExists which checks for the existence
of a given table and returns 1 or 0 accordingly. This allows us to
check for the existence of a given table when doing operations on
tables which may not exist in a given database which, in turn, will
reduce the number of red errors which show up after an upgrade.

An example of its use is included in this patch.

Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
Comment 5 Paul Poulain 2012-04-13 14:57:54 UTC
QA comment: small new sub that will be usefull for table existence checking. Should be independant from mysql if i'm not mistaking

passed QA
Comment 6 Jared Camins-Esakov 2012-12-31 00:52:11 UTC
There have been no further reports of problems so I am marking this bug resolved.