Inserting, update and deleteting a database under conditions
Inserting, update and deleteting a database under conditions
am 09.01.2008 14:17:48 von skieros
Hello, i'am trying to perl code the following ideas i have commented
as remarks but my attempts were fruitless.
Its complicated and although i tried to work some code, my code does
not do what the remarks say.
#=========================================================== ====================
my @files = glob "$ENV{'DOCUMENT_ROOT'}/data/text/*.txt";
my @menu_files = map m{([^/]+)\.txt}, @files;
my @dbfiles = $db->do( 'SELECT title, body FROM articles' );
my $replace = $db->prepare( 'INSERT INTO article (title, body) VALUES
(?, ?)' );
foreach ( @menu_files ) {
#Check every filename(item in @menu_files) as well as its content
to see if is already inserted in table articles under columns title
and body
#============ INSERT NEW FILENAMES & CONTENTS INTO DATABASE IF ANY
=============
#If filename and content dont already exist in the db then do
insert them
#===== UPDATE THE DB ENTRY IF THERE IS A MODIFICATION IN A FILES
CONTENTS =====
#If filename exists in the db under column title but its content is
different from the database's content then update column body in the
db
#======== DELETE ANY DB ENTRY OF A FILENAME THATDOESNT EXIST ANY
MORE =========
#Delete all db records that doesnt have a corresponding filename in
the hdd
}
Re: Inserting, update and deleteting a database under conditions
am 09.01.2008 17:40:39 von smallpond
On Jan 9, 8:17 am, Nikos wrote:
> Hello, i'am trying to perl code the following ideas i have commented
> as remarks but my attempts were fruitless.
> Its complicated and although i tried to work some code, my code does
> not do what the remarks say.
> #=========================================================== ====================
>
> my @files = glob "$ENV{'DOCUMENT_ROOT'}/data/text/*.txt";
> my @menu_files = map m{([^/]+)\.txt}, @files;
>
> my @dbfiles = $db->do( 'SELECT title, body FROM articles' );
> my $replace = $db->prepare( 'INSERT INTO article (title, body) VALUES
> (?, ?)' );
>
> foreach ( @menu_files ) {
>
> #Check every filename(item in @menu_files) as well as its content
> to see if is already inserted in table articles under columns title
> and body
>
> #============ INSERT NEW FILENAMES & CONTENTS INTO DATABASE IF ANY
> =============
> #If filename and content dont already exist in the db then do
> insert them
>
> #===== UPDATE THE DB ENTRY IF THERE IS A MODIFICATION IN A FILES
> CONTENTS =====
> #If filename exists in the db under column title but its content is
> different from the database's content then update column body in the
> db
>
> #======== DELETE ANY DB ENTRY OF A FILENAME THATDOESNT EXIST ANY
> MORE =========
> #Delete all db records that doesnt have a corresponding filename in
> the hdd
>
> }
It sounds like you just want to make the db match the directories.
Why not just drop the tables and recreate them from your globs?
--S
Re: Inserting, update and deleteting a database under conditions
am 09.01.2008 17:47:03 von Michele Dondi
On Wed, 9 Jan 2008 05:17:48 -0800 (PST), Nikos
wrote:
>Hello, i'am trying to perl code the following ideas i have commented
>as remarks but my attempts were fruitless.
Nik,
before reposting your question verbatim here, you should let people
know that you asked it in perlmonks first. So people will know what
that has been told you, and you will save them some duplication of
efforts:
http://perlmonks.org/?node_id=661326
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Re: Inserting, update and deleteting a database under conditions
am 11.01.2008 13:33:23 von skieros
On 9 Éá=ED, 18:47, Michele Dondi wrote:
> On Wed, 9 Jan 2008 05:17:48 -0800 (PST), Nikos
> wrote:
> before reposting your question verbatim here, you should let people
> know that you asked it in perlmonks first. So people will know what
> that has been told you, and you will save them some duplication of
> efforts:
Sorry Michael i asked there and here at the sametime in case my
question ouldn't be answered there, and it wasnt. can you help?
Re: Inserting, update and deleteting a database under conditions
am 11.01.2008 13:38:12 von skieros
On 9 Éá=ED, 18:40, smallpond wrote:
>
> It sounds like you just want to make the db match the directories.
> Why not just drop the tables and recreate them from your globs?
Yes that would be the easiest thing to do bu because that code would
run every time my index.pl runs that would sow down the scripts if it
needed dropping all the tables in the db recreate them then open all
files and then also fill in the tables will ALL information regarding
filenames and corresponding file contents. iam already doing this in
my other script called init.pl an my index pl i just want to keep
things synchronized among db anf hdd. :) Here is my int.pl code uses
to do what you described.
#===========3D INSERTING MULTIPLE FILENAMES & CONTENTS I=
NTO DATABASE
=============3D
my $data;
my $insert =3D $db->prepare( 'INSERT INTO articles (title, body) VALUES
(?, ?)' );
my @files =3D glob "$ENV{'DOCUMENT_ROOT'}/data/text/*.txt";
foreach (@files)
{
open FILE, "$_" or die $!;
Encode::from_to($_, 'ISO-8859-7', 'utf-8'); #Convert the
filename to utf8 encoding
($_) =3D map m{([^/]+)\.txt}, $_; #Strip out of the
string the path and extension leaving only the filename intact
$data =3D ; #Grab the whole
file contents at once
$insert->execute($_, $data) or print $db->errstr;
close FILE;
}
Re: Inserting, update and deleteting a database under conditions
am 11.01.2008 21:33:16 von Michele Dondi
On Fri, 11 Jan 2008 04:33:23 -0800 (PST), Nikos
wrote:
>> before reposting your question verbatim here, you should let people
>> know that you asked it in perlmonks first. So people will know what
>> that has been told you, and you will save them some duplication of
>> efforts:
>
>Sorry Michael i asked there and here at the sametime in case my
>question ouldn't be answered there, and it wasnt. can you help?
I'm afraid I can't, since it seems to me that your question *was*
answered there. But since this differs from your own perception, I
doubt I can add anything. It would be nice of you to specify, instead,
*what* of those answers did failt o satisfy you.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,