Bug 7902 - Adding Function to Check for Existence of Tables
Summary: Adding Function to Check for Existence of Tables
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Database (show other bugs)
Version: 3.8
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Chris Nighswonger
QA Contact: Ian Walls
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-05 13:39 UTC by Chris Nighswonger
Modified: 2013-12-05 20:04 UTC (History)
2 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Bot Control: ---
When did the bot last check this:
Who signed the patch off:
Text to go in the release notes:


Attachments
Patch to add feature (3.84 KB, patch)
2012-04-05 13:41 UTC, Chris Nighswonger
Details | Diff | Splinter Review
Bug 7902 - Adding Function to Check for Existence of Tables (3.90 KB, patch)
2012-04-05 14:07 UTC, Jared Camins-Esakov
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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.