Loading ...
Sorry, an error occurred while loading the content.

[Half-OT] Perl DBI, Mysql

Expand Messages
  • David Francos (XayOn)
    Hi there, I ve been using plain text databases for a while, but now, I think I ll go to mysql (It s for a web app so I prefer using mysql). I ve been watching
    Message 1 of 4 , Apr 3, 2008
    • 0 Attachment
      Hi there, I've been using plain text databases for a while, but now, I
      think I'll go to mysql (It's for a web app so I prefer using mysql).

      I've been watching DBI and so on, but I'm not sure how to handle something:
      Write on a column an element as the first one in the column, replacing
      the others.

      Options I've tought:
      If possible do it with mysql -> OT Part.
      If not, Do it with perl, but... How? Must I just extract everything
      from the table, process it and rewrite it? Hope don't because this is heavy.

      Thanks a lot.
    • Jenda Krynicky
      From: David Francos (XayOn) ... I m afraid you will have to explain this better. I have no idea whatsoever what do you want to do and I
      Message 2 of 4 , Apr 4, 2008
      • 0 Attachment
        From: "David Francos (XayOn)" <yo.orco@...>
        > Hi there, I've been using plain text databases for a while, but now, I
        > think I'll go to mysql (It's for a web app so I prefer using mysql).
        >
        > I've been watching DBI and so on, but I'm not sure how to handle something:
        > Write on a column an element as the first one in the column, replacing
        > the others.

        I'm afraid you will have to explain this better. I have no idea
        whatsoever what do you want to do and I think others are in the same
        situation.

        Jenda
        ===== Jenda@... === http://Jenda.Krynicky.cz =====
        When it comes to wine, women and song, wizards are allowed
        to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery
      • David Francos (XayOn)
        ... Thanks a lot, you re right. I don t know how to exactly explain it but i ll send you an example. This is the database table Thing|| Contint Thang|| Contant
        Message 3 of 4 , Apr 4, 2008
        • 0 Attachment
          Jenda Krynicky wrote:
          >
          > From: "David Francos (XayOn)" <yo.orco@...>
          > > Hi there, I've been using plain text databases for a while, but now, I
          > > think I'll go to mysql (It's for a web app so I prefer using mysql).
          > >
          > > I've been watching DBI and so on, but I'm not sure how to handle
          something:
          > > Write on a column an element as the first one in the column, replacing
          > > the others.
          >
          > I'm afraid you will have to explain this better. I have no idea
          > whatsoever what do you want to do and I think others are in the same
          > situation.

          Thanks a lot, you're right. I don't know how to exactly explain it but
          i'll send you an example.

          This is the database table

          Thing|| Contint
          Thang|| Contant
          Thong|| Contont
          Thung|| Contunt

          And I want to add something to it, and this something to be in the first
          place.

          Theng||Content
          Thing||Contint
          Thang||Contant
          Thong||Contont
          Thung||Contunt

          That way if I read the first 3 elementes, everytime I add an element, it
          will be shown the first

          This is because I was having fun programming a Blog (GPL'd), but I've
          seen It will be more eficient, easier, and lighter if I use a database
          instead of hundreds of text files.

          I know, I know, I should have said it before, sorry ;)
        • Jenda Krynicky
          From: David Francos (XayOn) ... Table is a set. A set of rows. Not an ordered list. While it has to give you the rows in some order (and
          Message 4 of 4 , Apr 4, 2008
          • 0 Attachment
            From: "David Francos (XayOn)" <yo.orco@...>
            > Jenda Krynicky wrote:
            > >
            > > From: "David Francos (XayOn)" <yo.orco@...>
            > > > Hi there, I've been using plain text databases for a while, but now, I
            > > > think I'll go to mysql (It's for a web app so I prefer using mysql).
            > > >
            > > > I've been watching DBI and so on, but I'm not sure how to handle
            > something:
            > > > Write on a column an element as the first one in the column, replacing
            > > > the others.
            > >
            > > I'm afraid you will have to explain this better. I have no idea
            > > whatsoever what do you want to do and I think others are in the same
            > > situation.
            >
            > Thanks a lot, you're right. I don't know how to exactly explain it but
            > i'll send you an example.
            >
            > This is the database table
            >
            > Thing|| Contint
            > Thang|| Contant
            > Thong|| Contont
            > Thung|| Contunt
            >
            > And I want to add something to it, and this something to be in the first
            > place.
            >
            > Theng||Content
            > Thing||Contint
            > Thang||Contant
            > Thong||Contont
            > Thung||Contunt
            >
            > That way if I read the first 3 elementes, everytime I add an element, it
            > will be shown the first

            Table is a set. A set of rows. Not an ordered list. While it has to
            give you the rows in some order (and usualy the order is defined) it
            will NOT be the order in which they were inserted, unless you
            specifically ask the database to keep track of the insertion order
            using autonumbered fields or sequences and do specify that the
            "clustered index" is this ID. And there's definitely no "insert this
            row just before this one".

            In either case if you need to receive the rows in some specific order
            you should always specify that order. And if you need them in the
            reverse order than they were inserted you need to keep the insertion
            order in the table

            I don't know mysql syntax so I'll use the MSSQL one, but you need
            something like:

            CREATE TABLE Things (
            Id Int Identity(1,1) NOT NULL,
            Name varchar(50),
            Value varchar(8000),
            CONSTRAINT [PK_SITE] PRIMARY KEY CLUSTERED ([SITEID])
            );

            and then

            INSERT INTO Things (Name, Value) VALUES ( 'Thung', 'Contunt')
            INSERT INTO Things (Name, Value) VALUES ( 'Thong', 'Contont')
            INSERT INTO Things (Name, Value) VALUES ( 'Thang', 'Contant')
            INSERT INTO Things (Name, Value) VALUES ( 'Thing', 'Contint')

            INSERT INTO Things (Name, Value) VALUES ( 'Theng', 'Content')

            and

            SELECT TOP 3 Name, Value
            FROM Things
            ORDER BY Id Desc

            And then when you find out you need to order the rows by Name:

            SELECT TOP 3 Name, Value
            FROM Things
            ORDER BY Name

            etc.

            Jenda


            ===== Jenda@... === http://Jenda.Krynicky.cz =====
            When it comes to wine, women and song, wizards are allowed
            to get drunk and croon as much as they like.
            -- Terry Pratchett in Sourcery
          Your message has been successfully submitted and would be delivered to recipients shortly.