Unix Technical Forum

Newbie needs code clarified

This is a discussion on Newbie needs code clarified within the MySQL forums, part of the Database Server Software category; --> I placed a "got it" comment on the lines where I understand the What AND Why. For all others, ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-24-2008, 06:09 AM
Mo
 
Posts: n/a
Default Newbie needs code clarified

I placed a "got it" comment on the lines where I understand the What
AND Why.
For all others, I had a little trouble fully comprehending what I
found in the MySQL Manual, so I'm looking for some further
explanation.

Feel free to explain as if I were completely daft, because sometimes,
I fear I may be ;-)

***START CODE***

drop table if exists
Dates; // got it
create table Dates
( // got it
id int(11) not null auto_increment primary key, // got it
dt datetime not NULL) // got it
engine=myisam; // why declare?
delimiter $
$ // what
and why?
drop procedure if exists make_dates $$ // why end
in $$?
CREATE PROCEDURE make_dates(max_recs int) // what is (max_recs int)
all about?
begin //
got it
DECLARE start_dt datetime; // got it
DECLARE numrecs int default 1; // got it
SET start_dt = date_format( now() - interval max_recs minute, '%Y-%m-
%d %H:%i:00');
//
i need a further explanation for "interval"
INSERT into Dates (dt) values (start_dt ); // got it
WHILE numrecs < max_recs // got it
DO //
got it
INSERT into Dates (dt) // got it
SELECT dt + interval ( numrecs ) minute
//
please explain "( numrecs ) minute"
FROM dates; // got it
SELECT count(*) into numrecs // should this become another INSERT
statement?
FROM dates; // got it
SELECT numrecs; // why?
end WHILE; // got
it
end $$delimiter;

***END CODE***

This code is from: http://datacharmer.blogspot.com/2006...s-quickly.html,
which I was directed to from another post.
I thought I wasn't going to need to use this, but after all, it turns
out that I may.
I'd like to gain an understanding so that I can confidently customize
it to our use.

~Mo
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-24-2008, 06:10 AM
JRough
 
Posts: n/a
Default Re: Newbie needs code clarified

On May 21, 2:29 pm, Mo <Mehile.Orl...@gmail.com> wrote:
> I placed a "got it" comment on the lines where I understand the What
> AND Why.
> For all others, I had a little trouble fully comprehending what I
> found in the MySQL Manual, so I'm looking for some further
> explanation.
>
> Feel free to explain as if I were completely daft, because sometimes,
> I fear I may be ;-)
>
> ***START CODE***
>
> drop table if exists
> Dates; // got it
> create table Dates
> ( // got it
> id int(11) not null auto_increment primary key, // got it
> dt datetime not NULL) // got it
> engine=myisam; // why declare?
> delimiter $
> $ // what
> and why?
> drop procedure if exists make_dates $$ // why end
> in $$?
> CREATE PROCEDURE make_dates(max_recs int) // what is (max_recs int)
> all about?
> begin //
> got it
> DECLARE start_dt datetime; // got it
> DECLARE numrecs int default 1; // got it
> SET start_dt = date_format( now() - interval max_recs minute, '%Y-%m-
> %d %H:%i:00');
> //
> i need a further explanation for "interval"
> INSERT into Dates (dt) values (start_dt ); // got it
> WHILE numrecs < max_recs // got it
> DO //
> got it
> INSERT into Dates (dt) // got it
> SELECT dt + interval ( numrecs ) minute
> //
> please explain "( numrecs ) minute"
> FROM dates; // got it
> SELECT count(*) into numrecs // should this become another INSERT
> statement?
> FROM dates; // got it
> SELECT numrecs; // why?
> end WHILE; // got
> it
> end $$delimiter;
>
> ***END CODE***
>
> This code is from:http://datacharmer.blogspot.com/2006...s-quickly.html,
> which I was directed to from another post.
> I thought I wasn't going to need to use this, but after all, it turns
> out that I may.
> I'd like to gain an understanding so that I can confidently customize
> it to our use.
>
> ~Mo


You would probably get more help if you asked one major question at a
time.
Try to understand what one section of code does and if you have
questions ask them underneath the code all together in one place.
The part that you get is immaterial, the part you don't get is what
you want to focus on.
The code is hard to read with the "got its" added after it goes
through the email it gets wrapped and the lines break different than
when you said it.
Try to keep your code as clean as possible so the people helping you
don't have to squint :-)

Where you say " I need further explanation for interval" that should
be at the bottom so people can read your code.
It is just to difficult to try to help you. Try rephrazing your
questions.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:10 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com