Gossamer Forum
Home : General : Databases and SQL :

Create an inital record in table when installing

 
Create an inital record in table when installing
This sounded easy, but I think I am doing it wrong.

I want to create an inital (default) record in a table when it is first created. Do I have to do this with a seperate ADD statement, or can this be done in the CREATE somehow?

This particular table should only ever have one record in it... so I dont want to really ADD another row, just set the first one if it does not already exist.

Does that make sense?

Many thanks!


Edit: I have semi solved this just be checking the number of rows, and if less than 1, doing an update on the table....


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jun 6, 2002, 12:14 PM
 
Re: [Ian] Create an inital record in table when installing In reply to
Just add an INSERT into the code.

If this is links sql you'd create the table then just do:

$DB->table($table)->insert( $hashref );
 
Re: [Paul] Create an inital record in table when installing In reply to
Hi Paul, yep, its Links SQL (as always for meSmile).

Quote:
$DB->table($table)->insert( $hashref );


I will play with this... thanks.


http://www.iuni.com/...tware/web/index.html
Links Plugins
 
Re: [Ian] Create an inital record in table when installing In reply to
Say your table had two columns A and B and the table was called FOO you'd use:

$DB->table('FOO')->insert( { A => 1, B => 2 } );
 
Re: [Paul] Create an inital record in table when installing In reply to
A => 1 the 1 being whatever default I want it to initially set it to?

I have done something similar in my repair table function (which is meant to be done right after the user installs the plugin)...

my $numrecords = $st->count;
if ($numrecords < 1) {
$st->insert ( {
Announcements => "None."
}) or die $GT::SQL::error;
print "EM Settings table reset to defaults.<br><hr>";
}

This forced all the records to go to their defaults just by modifying one of them.... great, but I thought SQL might have had a function already for setting the first record to defaults. I guess I could move this to the table creation section too.


http://www.iuni.com/...tware/web/index.html
Links Plugins
 
Re: [Ian] Create an inital record in table when installing In reply to
links SQL is a database program, how does it compare to Postgres which is what I use right now...

As for Ian, if you want to input a number and get it to increment (I have found this to be the most popular method for interfacing using primary keys) you can just use a SEQUENCE. Just so that you can keep your options open Wink.



Crapshoot70 (this isn't my real name)
--
I don't like anyone...but everyone LOVES me Unsure
--
AKA...The Post Pirate Pirate
 
Re: [Crapshoot70] Create an inital record in table when installing In reply to
Links SQL, among other GT products, works with MySQL, Postgres, SQL Server, and Oracle. I believe I mentioned this to you in a previous thread you started. Again, check out the GT products page, look at the system requirements section.
========================================
Buh Bye!

Cheers,
Me
 
Re: [Stealth] Create an inital record in table when installing In reply to
maybe you are thinking of someone else, cuz you never told me anything of the sort. Tongue



Crapshoot70 (this isn't my real name)
--
I don't like anyone...but everyone LOVES me Unsure
--
AKA...The Post Pirate Pirate
 
Re: [Crapshoot70] Create an inital record in table when installing In reply to
Uh oh, you better go and put on your bullet proof vest.
 
Re: [Crapshoot70] Create an inital record in table when installing In reply to
Guess you don't read replies in threads that YOU start...

GO here: http://www.gossamer-threads.com/...;;page=unread#unread

And it WAS YOU that I was replying to IN that THREAD! Tongue Wink

Suggestion: Take time to read replies in threads that you start and others.
========================================
Buh Bye!

Cheers,
Me
 
Create an inital record in table when installing In reply to
Hey guys, I did not mean to start WW3. Just create a record in a table...


http://www.iuni.com/...tware/web/index.html
Links Plugins
 
Re: [Stealth] Create an inital record in table when installing In reply to
Ok...but even when I read that again...that was a pretty vague response...



Crapshoot70 (this isn't my real name)
--
I don't like anyone...but everyone LOVES me Unsure
--
AKA...The Post Pirate Pirate
 
Re: [Crapshoot70] Create an inital record in table when installing In reply to
What's vague about stating that GT products (SQL-based) are written to work for MySQL, SQL Server, Oracle, and POSTGRES...as I stated in that thread, and re-stated in this thread??? Huh? Don't see anything vague about it....Tongue
========================================
Buh Bye!

Cheers,
Me
 
Re: [Stealth] Create an inital record in table when installing In reply to
Lets just be happy....arguing gets everyone nowhere as I've often found out.
 
Re: [Paul] Create an inital record in table when installing In reply to
Here here!

Even joking around can be taken the wrong way sometimes. But I think chit-chat or arguing does not belong in the thread, and arguing not on this forum.

I know we all get frustrated, jealous and all the range of things us humans get at times... (I know I do).

I am only commenting, as this was the thread I started to create a record in a table.... and the topic seems to have strayed somewhat.

Cool


http://www.iuni.com/...tware/web/index.html
Links Plugins
 
Re: [Paul] Create an inital record in table when installing In reply to
Quote:
Lets just be happy....arguing gets everyone nowhere as I've often found out.

Haha! LOL! Smile Coming from you...haha! Now, that is a joke! Thanks for the laugh...sure needed that. haha!
========================================
Buh Bye!

Cheers,
Me
 
Re: [Stealth] Create an inital record in table when installing In reply to
Oh...I see what you were saying...it just took like 3 days to sink in...

BTW...why the attitude Stealth?

What has gone so wrong in your life that you have to lash out at others???

Share it with the board or just let it eat you up inside...



Crapshoot70 (this isn't my real name)
--
I don't like anyone...but everyone LOVES me Unsure
--
AKA...The Post Pirate Pirate
 
Re: [Crapshoot70] Create an inital record in table when installing In reply to
Attitude? Check your own...Tongue I was helpful by posting the same answer to you three times and you still didn't get it nor were appreciative of the time and effort I made to answer your question (even the first time). Telling me my answer was "vague" was not appropriate, IMO. I clearly answered your question more than once, which I will not do in the future.

Goes both ways, ya know...Check your attitude as well.
========================================
Buh Bye!

Cheers,
Me
 
Re: [Ian] Create an inital record in table when installing In reply to
Locked this before it gets out of hand.

Cheers,

Alex
--
Gossamer Threads Inc.