eGospodarka.pl
eGospodarka.pl poleca

eGospodarka.plGrupypl.comp.programmingWypalenie - czy ktoś z Was się z nim zetknął?Re: Wypalenie - czy ktoś z Was się z nim zetknął?
  • Path: news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.
    atman.pl!news.task.gda.pl!not-for-mail
    From: "AK" <n...@n...com>
    Newsgroups: pl.comp.programming
    Subject: Re: Wypalenie - czy ktoś z Was się z nim zetknął?
    Date: Thu, 27 Sep 2012 12:24:07 +0200
    Organization: CI TASK http://www.task.gda.pl/
    Lines: 132
    Message-ID: <k419ga$3no$1@news.task.gda.pl>
    References: <f...@d...googlegroups.com>
    <k3t757$hju$1@node2.news.atman.pl> <k3t85a$cjg$1@news.task.gda.pl>
    <k3vmgt$s5m$1@node2.news.atman.pl> <k4157b$p6p$1@news.task.gda.pl>
    <s...@j...net>
    NNTP-Posting-Host: ppp142003.ostnet.pl
    Mime-Version: 1.0
    Content-Type: text/plain; format=flowed; charset="iso-8859-2"; reply-type=original
    Content-Transfer-Encoding: 8bit
    X-Trace: news.task.gda.pl 1348741450 3832 62.133.142.3 (27 Sep 2012 10:24:10 GMT)
    X-Complaints-To: a...@n...task.gda.pl
    NNTP-Posting-Date: Thu, 27 Sep 2012 10:24:10 +0000 (UTC)
    In-Reply-To: <s...@j...net>
    X-Priority: 3
    X-MSMail-Priority: Normal
    X-Newsreader: Microsoft Windows Mail 6.0.6002.18197
    X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6002.18463
    Xref: news-archive.icm.edu.pl pl.comp.programming:199656
    [ ukryj nagłówki ]

    Użytkownik "Stachu 'Dozzie' K." <d...@g...eat.some.screws.spammer.invalid> napisał:

    >>> Może za mało SQLa ;)
    >>
    >> Tak ? No to zaprogramuj drzewo w zwyklym klasycznym SQL-lu ;)
    >
    > http://www.slideshare.net/billkarwin/sql-antipattern
    s-strike-back
    > Slajdy 48 i późniejsze.

    No popatrz popatrz... (przejrzalem tylko poczatkowe chyba 20)
    Grzebales mi po kodzie sprzed prawie 10 lat ? (sprzed wypalenia ?:).

    import Attr
    from Query import *


    TYPEID_CONTAINER = -1
    TYPEID_OBJECT = 0
    TYPEID_INTEGER = 1
    TYPEID_REAL = 2
    TYPEID_LOGICAL = 3
    TYPEID_DATE = 4
    TYPEID_TEXT = 5
    TYPEID_PARAGRAPH = 6
    TYPEID_BINARY = 7


    def createBase(server, database, user=None, password=None):
    structure = [
    '''
    CREATE TABLE AttributeTypes
    (
    ID INTEGER NOT NULL UNIQUE,
    CODE VARCHAR(16) NOT NULL UNIQUE,
    Name VARCHAR(40) NOT NULL UNIQUE,
    Description VARCHAR(40),
    FUN_ToValue VARCHAR(40),
    FUN_FromValue VARCHAR(40),
    CONSTRAINT AttributeTypesPrimKey PRIMARY KEY (ID)
    )
    ''',
    '''
    CREATE TABLE AttributeDefinitions
    (
    ID INTEGER NOT NULL UNIQUE,
    CODE VARCHAR(16) NOT NULL UNIQUE,
    Name VARCHAR(40) NOT NULL UNIQUE,
    Description VARCHAR(40),
    TypeID INTEGER NOT NULL,
    CONSTRAINT AttributeDefinitionsPrimKey PRIMARY KEY (ID),
    CONSTRAINT AttributeDefinitionsForiKey FOREIGN KEY (TypeID) REFERENCES
    AttributeTypes (ID)
    )
    ''',
    '''
    CREATE TABLE AttributeValues
    (
    ID INTEGER NOT NULL UNIQUE,
    Value VARCHAR(80),
    BinaryID INTEGER,
    DefID INTEGER NOT NULL,
    CONSTRAINT AttributeValuesPrimKey PRIMARY KEY (ID),
    CONSTRAINT AttributeValuesForiKey FOREIGN KEY (DefID) REFERENCES
    AttributeDefinitions (ID)
    )
    ''',
    '''
    CREATE INDEX AttributeValuesIdx_Value ON AttributeValues (Value)
    ''',
    '''
    CREATE TABLE AttributeTrees
    (
    ID INTEGER NOT NULL UNIQUE,
    Tree INTEGER NOT NULL,
    Lft FLOAT NOT NULL UNIQUE,
    Rgt FLOAT NOT NULL UNIQUE,
    ValueID INTEGER NOT NULL,
    CONSTRAINT AttributeTreesOrderOk CHECK (Lft < Rgt),
    CONSTRAINT AttributeTreesPrimKey PRIMARY KEY (ID),
    CONSTRAINT AttributeTreesForiKey FOREIGN KEY (ValueID) REFERENCES AttributeValues
    (ID)
    )
    ''',
    '''
    CREATE INDEX AttributeTreesIdx_Tree ON AttributeTrees (Tree)
    ''',
    '''
    CREATE VIEW Attributes AS
    SELECT
    NodeTrees.ID AS ID,
    NodeTrees.Lft AS Lft,
    NodeTrees.Rgt AS Rgt,
    NodeValues.ID AS ValueID,
    NodeValues.Value AS Value,
    NodeValues.BinaryID AS BinaryID,
    NodeDefinitions.ID AS DefID,
    NodeDefinitions.CODE AS DefCODE,
    NodeDefinitions.Name AS DefName,
    NodeTypes.ID AS TypeID,
    NodeTypes.CODE AS TypeCODE,
    NodeTypes.Name AS TypeName,
    ParentTrees.ID AS ParentID,
    ParentTrees.Lft AS ParentLft,
    ParentTrees.Rgt AS ParentRgt,
    ParentValues.ID AS ParentValueID,
    ParentValues.Value AS ParentValue,
    ParentValues.BinaryID AS ParentBinaryID,
    ParentDefinitions.ID AS ParentDefID,
    ParentDefinitions.CODE AS ParentDefCODE,
    ParentDefinitions.Name AS ParentDefName,
    ParentTypes.ID AS ParentTypeID,
    ParentTypes.CODE AS ParentTypeCODE,
    ParentTypes.Name AS ParentTypeName,
    NodeTrees.Tree AS Tree
    FROM (AttributeTrees AS NodeTrees
    LEFT JOIN AttributeTrees AS ParentTrees
    ON (SELECT MAX(Lft) FROM AttributeTrees
    WHERE Lft < NodeTrees.Lft AND Rgt > NodeTrees.Lft) = ParentTrees.Lft)
    LEFT JOIN (AttributeValues AS NodeValues
    JOIN (AttributeDefinitions AS NodeDefinitions
    JOIN AttributeTypes AS NodeTypes
    ON NodeDefinitions.TypeID = NodeTypes.ID)
    ON NodeValues.DefID = NodeDefinitions.ID)
    ON (NodeTrees.ValueID = NodeValues.ID)
    LEFT JOIN (AttributeValues AS ParentValues
    JOIN (AttributeDefinitions AS ParentDefinitions
    JOIN AttributeTypes AS ParentTypes
    ON ParentDefinitions.TypeID = ParentTypes.ID)
    ON ParentValues.DefID = ParentDefinitions.ID)
    ON ParentTrees.ValueID = ParentValues.ID

    [...]

    AK

Podziel się

Poleć ten post znajomemu poleć

Wydrukuj ten post drukuj


Następne wpisy z tego wątku

Najnowsze wątki z tej grupy


Najnowsze wątki

Szukaj w grupach

Eksperci egospodarka.pl

1 1 1

Wpisz nazwę miasta, dla którego chcesz znaleźć jednostkę ZUS.

Wzory dokumentów

Bezpłatne wzory dokumentów i formularzy.
Wyszukaj i pobierz za darmo: