To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here

http://justlinux.com/   Mon, 06-Sep-2010 01:02:01 GMT
         internet.com

Go Back   JustLinux Forums > Community Help: Check the Help Files, then come here to ask! > Programming/Scripts

Programming/Scripts Perl, Python, C/C++, Java, CGI, shell, etc. Share your code!

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 11-20-2005, 09:14 AM
arioch's Avatar
arioch arioch is offline
Deathmetal warhead
 
Join Date: Aug 2002
Posts: 466
database suggestion

I am about to establish a big metalband database in 3 rd. nf with a total of 19 tables and just found out that MySQL has some nasty limitations in regards to the use of keys, and can't insert or extract data from several tables at the same time.

I would like to be able to copy the primary key to the relevant subtables - unless just putting an auto incremented numberfield in each table and then join the tables together through them, is ok.

What's out there that's OSS and fits the bill? What about the database in OO2? It's supposed to be an old discarded IBM-thing as far as I know...

I am a complete database newbie and badly need a hint here.

Later.
__________________
debian with no BS and all plugins running? http://www.mepis.org
------------------------------------------------------
So the EU is not a Euronation-forming project? Then why do we have to adopt a new constitution, flag and currency? And why are our borders suddenly gone and why do we suddenly have a president?
Reply With Quote
  #2  
Old 11-20-2005, 02:46 PM
bwkaz bwkaz is offline
Moderator
 
Join Date: Apr 2001
Location: SF Bay Area, CA
Posts: 14,950
Quote:
Originally Posted by arioch
and just found out that MySQL has some nasty limitations in regards to the use of keys,
What are they? It's done everything I needed it to do, for whatever that's worth.

Quote:
and can't insert or extract data from several tables at the same time.
No, it can't insert data into multiple tables at once, but that's not needed anyway. (Just insert data into the primary table, then into the child table. Python's MySQL interface even has a way to get at the key-field value of the record you just inserted, if it's an autoincrement field. So you can use this to put the same value into the foreign-key fields in the child table.)

But it definitely can extract data from >1 table -- I've done inner, left outer, and right outer joins several times from it.
__________________
"Quando omni flunkus moritati" -- Possum Lodge motto -- Loose translation: "When all else fails, play dead."

Registered Linux User #219692
Please take a look at the Posting Guidelines, to help us help you!
Reply With Quote
  #3  
Old 11-20-2005, 06:19 PM
arioch's Avatar
arioch arioch is offline
Deathmetal warhead
 
Join Date: Aug 2002
Posts: 466
Thanx for responding.

I've been told that primary keys can't be copied to other tables as foreign keys.

"No, it can't insert data into multiple tables at once, but that's not needed anyway. (Just insert data into the primary table, then into the child table."

Not very practical when you have six or more separate tables under the primary table. I don't want to repeat the same process seven times in a row. I want to insert data once and be over with it, no matter how many tables are involved.
__________________
debian with no BS and all plugins running? http://www.mepis.org
------------------------------------------------------
So the EU is not a Euronation-forming project? Then why do we have to adopt a new constitution, flag and currency? And why are our borders suddenly gone and why do we suddenly have a president?

Last edited by arioch; 11-20-2005 at 06:21 PM.
Reply With Quote
  #4  
Old 11-20-2005, 10:58 PM
bwkaz bwkaz is offline
Moderator
 
Join Date: Apr 2001
Location: SF Bay Area, CA
Posts: 14,950
Quote:
I've been told that primary keys can't be copied to other tables as foreign keys.
I believe that's wrong, because I've done it several times. But you have to be using the right language -- not all language bindings allow you to find out what the most-recent PK value was, so you can't copy that value into the child tables when you use some languages.

And I've never seen any relational database that allows you to insert into more than one table in one statement, for whatever that's worth.
__________________
"Quando omni flunkus moritati" -- Possum Lodge motto -- Loose translation: "When all else fails, play dead."

Registered Linux User #219692
Please take a look at the Posting Guidelines, to help us help you!
Reply With Quote
  #5  
Old 11-21-2005, 02:49 AM
webwolf webwolf is offline
Registered User
 
Join Date: Oct 2005
Location: Nuernberg, Germany
Posts: 181
database suggestion

have a look at postgreSQL http://www.postgresql.org/
webwolf
__________________
Centos 4.1 athlon 2600 256MB DDRRAM on 240GB no windows allowed.
Debian 3.1 etch CeleronM 1500 Mhz 192MB RAM 40GB gericom notebook (one again no windows allowed)
Reply With Quote
  #6  
Old 11-21-2005, 07:57 AM
arioch's Avatar
arioch arioch is offline
Deathmetal warhead
 
Join Date: Aug 2002
Posts: 466
I don't know if we're talking a bit "off" each other here, so allow me to elaborate: I just want to recieve userdata from an XHTML form using PHP, and have everything transported into the respective tables at just one push of a button at the bottom of the form. That really isn't possible with MySQL?

Doesn't the key capabilities also depend on whether you use InnoDB as the engine or not?
__________________
debian with no BS and all plugins running? http://www.mepis.org
------------------------------------------------------
So the EU is not a Euronation-forming project? Then why do we have to adopt a new constitution, flag and currency? And why are our borders suddenly gone and why do we suddenly have a president?
Reply With Quote
  #7  
Old 11-21-2005, 07:36 PM
bwkaz bwkaz is offline
Moderator
 
Join Date: Apr 2001
Location: SF Bay Area, CA
Posts: 14,950
Quote:
Originally Posted by arioch
I don't know if we're talking a bit "off" each other here, so allow me to elaborate: I just want to recieve userdata from an XHTML form using PHP, and have everything transported into the respective tables at just one push of a button at the bottom of the form. That really isn't possible with MySQL?
Oh, that's what you meant. Of course it's possible.

You need to run multiple SQL "insert" statements in your PHP script, though, just like you'd have to do with any other database. (And note that PHP's default interface to MySQL is really rather poor -- for example, it lacks the ability to use parameters, and forces you to concatenate user-input with your SQL statement, which has inherent security problems -- Python's is much better. PHP has an alternative MySQL interface that's also much better (perhaps related to pear?).)

Quote:
Doesn't the key capabilities also depend on whether you use InnoDB as the engine or not?
Yes, it does depend on your engine -- but then, why would you want to use flat files with no real indexing, anyway? (Since that's what the old non-InnoDB backend basically is.) You could use Berkeley DB as a backend also; that should support keys and whatnot, I think.
__________________
"Quando omni flunkus moritati" -- Possum Lodge motto -- Loose translation: "When all else fails, play dead."

Registered Linux User #219692
Please take a look at the Posting Guidelines, to help us help you!
Reply With Quote
  #8  
Old 11-21-2005, 08:50 PM
arioch's Avatar
arioch arioch is offline
Deathmetal warhead
 
Join Date: Aug 2002
Posts: 466
Ah, at least now we're on the same page... So, no problem with using MySQL as it is out of the box, since InnoDB is the standard engine.

"You need to run multiple SQL "insert" statements in your PHP script."

I sort of knew it would be something like that, but something I read on the net made me question it. I was told that PHPmyadmin couldn't make foreign keys because MySQL didn't have that capacity.

Could I get you to dig up the name of that PHP SQL interface improvement? Do you know if it also does away with the risk of these SQL injection attacks? That would be really neat.
__________________
debian with no BS and all plugins running? http://www.mepis.org
------------------------------------------------------
So the EU is not a Euronation-forming project? Then why do we have to adopt a new constitution, flag and currency? And why are our borders suddenly gone and why do we suddenly have a president?

Last edited by arioch; 11-22-2005 at 10:48 AM.
Reply With Quote
  #9  
Old 11-22-2005, 08:41 PM
bwkaz bwkaz is offline
Moderator
 
Join Date: Apr 2001
Location: SF Bay Area, CA
Posts: 14,950
It definitely helps with SQL injection, if the SQL driver itself uses parameters instead of just concatenating for you. The MySQL C API allows parameters, and the server will do the substitution "safely", at least since MySQL 4.1 (which may be why the default PHP interface doesn't use them).

From looking around at php.net, it appears that MySQLI is the interface I'd use. It has some of what the Python interface has, at least:

http://www.php.net/manual/en/ref.mysqli.php

It does allow parameters, but you have to specifically ask for them (i.e., use the prepare() function, then bind all the params; don't use the query() function):

http://www.php.net/manual/en/functio...li-prepare.php

It's still (IMO anyway) easier in Python:

Code:
cn = MySQLdb.connection(stuff...)
username="bob"    # Or take it from CGI...

cursor = cn.cursor()
cursor.execute("select * from users where username=%s", (username,))

for row in cursor.fetchall():
    print str(row[0]) + str(row[1])
(Or whatever. You get the point, I think. Basically, parameters are handled by passing an optional tuple into the execute method -- no parameters, no tuple required.)
__________________
"Quando omni flunkus moritati" -- Possum Lodge motto -- Loose translation: "When all else fails, play dead."

Registered Linux User #219692
Please take a look at the Posting Guidelines, to help us help you!

Last edited by bwkaz; 11-22-2005 at 08:46 PM.
Reply With Quote
  #10  
Old 11-23-2005, 09:32 AM
arioch's Avatar
arioch arioch is offline
Deathmetal warhead
 
Join Date: Aug 2002
Posts: 466
Thanx for the info. Very valuable indeed.

If PHPmyadmin can't do foreign keys, can you name me an intuitive graphic app, that doesn't take too much study to start using, that can do this? Perhaps by drag'n'drop? What about OO2? Does it have that capacity? The new SimplyMEPIS is coming, up and it comes with OO2.
__________________
debian with no BS and all plugins running? http://www.mepis.org
------------------------------------------------------
So the EU is not a Euronation-forming project? Then why do we have to adopt a new constitution, flag and currency? And why are our borders suddenly gone and why do we suddenly have a president?
Reply With Quote
  #11  
Old 11-23-2005, 08:04 PM
bwkaz bwkaz is offline
Moderator
 
Join Date: Apr 2001
Location: SF Bay Area, CA
Posts: 14,950
I've never set up a MySQL database with OO.o -- last time I tried setting up any database at all with it, it was the "internal" database format, and it routinely crashed (though that was version 1.9.100, not 2). I'm not sure you can even set up a MySQL database from OO itself.

What I used was mysql-administrator (not mysqladmin; this is actually a separate package). It didn't do foreign keys correctly either, though, so I had to do them manually. I kept a SQL script around for future reference:

Code:
mysql <whatever options>
ALTER TABLE `<database>`.`<table>` ADD CONSTRAINT `<pick a name>`
    FOREIGN KEY `<same name as you chose above>` (`<column name>` [, `<column name>`...])
    REFERENCES `<primary key table>` (`(null)`)
    ON DELETE RESTRICT
    ON UPDATE RESTRICT;
Instead of RESTRICT, you can use either CASCADE or some other option(s) I don't remember ATM -- check the MySQL manual for the full syntax of those clauses.

Note especially the (`(null)`) in the REFERENCES clause -- this makes the foreign key reference the primary key of <primary key table>.

Oh, and wherever I have angle brackets in there, remove them. They're just an indication that you need to substitute something.
__________________
"Quando omni flunkus moritati" -- Possum Lodge motto -- Loose translation: "When all else fails, play dead."

Registered Linux User #219692
Please take a look at the Posting Guidelines, to help us help you!
Reply With Quote
  #12  
Old 11-23-2005, 08:56 PM
arioch's Avatar
arioch arioch is offline
Deathmetal warhead
 
Join Date: Aug 2002
Posts: 466
I am seriously contemplating coding the database by hand now... i just need clarification on one subject. The actual joining of two tables. Consider the two example-tables below:
Code:
CREATE TABLE album(
  id CHAR(10) NOT NULL PRIMARY KEY,
  title VARCHAR(100),
  artist VARCHAR(100)
);
CREATE TABLE track(
  album CHAR(10),
  dsk INTEGER,
  posn INTEGER,
  song VARCHAR(255),
  FOREIGN KEY (album) REFERENCES album(id)
);
How would the join code look for these two tables? And what kind of join would be the one to use here?

This is my first dive into "SQL-by-hand", so in layman's terms please...
__________________
debian with no BS and all plugins running? http://www.mepis.org
------------------------------------------------------
So the EU is not a Euronation-forming project? Then why do we have to adopt a new constitution, flag and currency? And why are our borders suddenly gone and why do we suddenly have a president?
Reply With Quote
  #13  
Old 11-24-2005, 04:49 AM
aNoob's Avatar
aNoob aNoob is offline
Yeah!I'm a n00b...
 
Join Date: May 2003
Location: Some Teritories
Posts: 367
You will most probably join them on id/album. Why don't you give the same name for the keys in your tables? Is much more easier to read. I would rewrite it like that

CREATE TABLE album(
album_id CHAR(10) NOT NULL PRIMARY KEY,
title VARCHAR(100),
artist VARCHAR(100)
);
CREATE TABLE track(
album_id CHAR(10) NOT NULL PRIMARY KEY,
track_id NOT NULL PRIMARY KEY,
dsk INTEGER ,
posn INTEGER,
song VARCHAR(255)
);

So for example, you have your Billy Idol Rebel Yell album and this one has number 5 as album_id and you want all the tracks from this album only:

SELECT * FROM track WHERE album_id = 5

I assume these are oversimplified tables because a track should have a name,duration etc. Unless you want to create another table track_details but then you should not hyper-normalize like that.
Well, if I said something stupid, please correct me.
__________________
_________________________
Registered Linux User #314213
_________________________
Desktop 1 : P4 3.2G HT 2GB TWINX CORSAIR 2X120GB S-ATA NV7800GT- Ubuntu 7.04 - Feisty Fawn
Desktop 2 : P4 2.4G 512MB SDRAM 60GB IntelGMA - Slackware 11 - Fluxbox
Reply With Quote
  #14  
Old 11-24-2005, 05:15 AM
ooagentbender's Avatar
ooagentbender ooagentbender is offline
Desperate Housenerd
 
Join Date: Jan 2004
Posts: 299
I've been using mysql and php alot lately and I think its a great solution to almost all database and webscripting needs. Just need to find out how to do it. good luck with your site and feel free to PM me with any other questions you come across aside from the ones you ask here.
__________________

Ubuntu Convert
Reply With Quote
  #15  
Old 11-24-2005, 01:12 PM
arioch's Avatar
arioch arioch is offline
Deathmetal warhead
 
Join Date: Aug 2002
Posts: 466
aNoob:

1) On which fields would you join them? "Album_id" to "album_id", or "album_id" to "track_id"?

I am sitting here looking at my homecooked OO databasediagram getting awfully confused now, I'm not even sure the design isn't flawed now
__________________
debian with no BS and all plugins running? http://www.mepis.org
------------------------------------------------------
So the EU is not a Euronation-forming project? Then why do we have to adopt a new constitution, flag and currency? And why are our borders suddenly gone and why do we suddenly have a president?
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 09:02 PM.

Help File Library
Distribution Specific
Shells
Compiling Kernels
Command Reference
Filesystems
More



internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
Free Newsletter
Server Daily


More Free Newsletters




internet.commerce
Be a Commerce Partner












Linux is a trademark of Linus Torvalds.

Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.7.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.