Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-06-2012, 04:44 AM   #1
LQ Newbie
Registered: Jun 2012
Posts: 5

Rep: Reputation: Disabled
To store user login info into sqlite3 using perl


I need to connect to SQLite db n store user login info using perl script.
The DB and the table is created.
Now I need to add a part to the code so that it shows the followings

1) 0 - No error
2) -1 - record already present, if one of the primary values are already there.

3) -2 - If any of the information is invalid or incomplete,

Please could anyone help me with hints or code?
I am new to programming.
Old 08-07-2012, 02:31 PM   #2
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Cool project, but not a trivial one for someone new to programming. (This means you've never programmed in Perl, SQL, or any language?)

It's going to be difficult to help you without any code context, so you may want to post what you've tried so far.
1 members found this post helpful.
Old 08-08-2012, 02:04 AM   #3
LQ Newbie
Registered: Jun 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
To store user login info into sqlite3 using perl Reply to Thread Logged in as dhriti Title: Me

Assuming there is a db called test.db with table Cars in SQLite.


use strict;
use DBI;

my $dbh = DBI->connect(
{ RaiseError => 1 }
) or die $DBI::errstr;

my $sth = $dbh->prepare( "SELECT * FROM Cars WHERE Id=1" );

my ($id, $name, $price) = $sth->fetchrow();
print "$id $name $price\n";


Now the condition is for each new entry to the DB table shouldn;t have same name or price.
If it matches, it should show error, n shouldn't give access to entry to the table.
what should be the logic?
Old 08-08-2012, 09:39 AM   #4
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
First, your code looks pretty good for a non programmer. It would be a lot easier to read if it were posted in [CODE] [/CODE] tags to preserve the formatting. Please edit your posts accordingly.
It seems to me that you you should be loading from the existing Db, those records that match any one of the fields of interest. If the returned dataset is non-empty, then you know that at least one record exists matching one of your fields, and you can exit with a '-1' exit code or return value. You will need to have something to search for, which can be specified by parameters passed from the commandline.
Code that looks something like this may help.
my $inputPrice = $ARGV[0];
my $inputName = $ARGV[1];

#  Compose a query string (assuming some table column names here)
my $queryString = "SELECT * from Cars WHERE Name like '%$inputName%' or Price like '%$inputPrice%'";
It isn't clear what is meant by 'information is invalid or incomplete'. I guess that one criterion is that both of the 'name' and 'price' arguments must be non-empty. Perhaps you have some criteria that evaluates the input for well-formedness, but you will need to expand on what those criteria are.

--- rod.
1 members found this post helpful.
Old 08-08-2012, 01:31 PM   #5
LQ Newbie
Registered: Jun 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thanks a lot. I got some idea. Yes its a existing DB and about the 3rd criterion what you have told is correct.
I will try now. Thank you both


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
need to get last login info of each user tahaz Linux - Newbie 19 05-30-2012 06:06 PM
Information store: What software could I use to store and access various info merixon Linux - Software 2 12-17-2008 11:51 AM
How do i store wep key and essid info? adam999 Fedora 1 09-27-2006 06:32 PM
Displaying the User info from Active Directory using php/perl pudhiyavan Linux - Software 1 06-22-2006 12:51 AM
Possible to store track/title info when converting from MP3 to CD Audio? JBailey742 Linux - Software 3 05-03-2006 06:52 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:59 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration