/*============================================================================ project: tracktype file: cddb-disc.sql author: Andrew Smith created: 2006-11-10 updated: 2007-01-01 language: PostgreSQL 8.1 licence: BSD (revised) NOTES Create a table and load the raw tracktype.org data. ------------------------------------------------------------------------------ Copyright (c) 2006,2007 Andrew Smith All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ============================================================================*/ ------------------------------------------------------------------------------ \set ON_ERROR_STOP yes CREATE DATABASE tracktype; \connect tracktype ------------------------------------------------------------------------------ CREATE TABLE iDisc ( fFileSize INTEGER NOT NULL, fDateTime INTEGER NOT NULL, pCategory INTEGER NOT NULL, fFileName INTEGER NOT NULL, pEncoding INTEGER, fLength INTEGER NOT NULL, fRevision INTEGER NOT NULL, fProcessor TEXT, fSubmitter TEXT, fDiscIds INTEGER[], fDiscTitle TEXT, fYear TEXT, fGenre TEXT, fDiscComment TEXT, fOffsets INTEGER[], fTrackTitles TEXT[], fTrackComments TEXT[], fDiscInfo TEXT, fVolumeInfo TEXT ); \! 7z e -so 'cddb-disc-20070101.7z' | psql -c "COPY iDisc FROM STDIN NULL ''" tracktype ALTER TABLE iDisc ADD PRIMARY KEY (fFileName,pCategory); ALTER TABLE iDisc CLUSTER ON iDisc_PKEY; ANALYZE iDisc; -- parse disc info field ----------------------------------------------------- CREATE OR REPLACE FUNCTION dDiscNumber(aText TEXT) RETURNS TEXT AS $$ DECLARE vText TEXT; BEGIN vText := LOWER(aText); vText := REPLACE(vText,'one','1'); vText := REPLACE(vText,'two','2'); vText := REPLACE(vText,'three','3'); vText := REPLACE(vText,'four','4'); vText := REPLACE(vText,'five','5'); vText := REPLACE(vText,'six','6'); vText := REPLACE(vText,'seven','7'); vText := REPLACE(vText,'eight','8'); vText := REPLACE(vText,'nine','9'); vText := REPLACE(vText,'ten','10'); vText := REPLACE(vText,'eleven','11'); vText := REPLACE(vText,'twelve','12'); vText := REPLACE(vText,'thirteen','13'); vText := REPLACE(vText,'disc',' '); vText := REPLACE(vText,'disk',' '); vText := REPLACE(vText,'cd',' '); vText := REPLACE(vText,'of',' '); vText := REPLACE(vText,'von',' '); vText := REPLACE(vText,'ii','2'); vText := REPLACE(vText,'i','1'); vText := CAST(SUBSTRING(vText FROM '[0-9]+') AS INTEGER); RETURN COALESCE(' (disc '||vText||')',''); END; $$ LANGUAGE plpgsql IMMUTABLE; ------------------------------------------------------------------------------ /*==========================================================================*/