Lines 672-678
Link Here
|
672 |
=cut |
672 |
=cut |
673 |
|
673 |
|
674 |
sub _initialize_db { |
674 |
sub _initialize_db { |
675 |
my ($self, $create_entry_p) = @_; |
675 |
my ($self) = @_; |
676 |
|
676 |
|
677 |
return 0 unless (defined($self->{_dbh})); |
677 |
return 0 unless (defined($self->{_dbh})); |
678 |
|
678 |
|
Lines 697-703
Link Here
|
697 |
|
697 |
|
698 |
my $sqlselect = "SELECT id FROM bayes_vars WHERE username = ?"; |
698 |
my $sqlselect = "SELECT id FROM bayes_vars WHERE username = ?"; |
699 |
|
699 |
|
700 |
my $sthselect = $self->{_dbh}->prepare_cached($sqlselect); |
700 |
my $sthselect = $self->{_dbh}->prepare($sqlselect); |
701 |
|
701 |
|
702 |
unless (defined($sthselect)) { |
702 |
unless (defined($sthselect)) { |
703 |
dbg("bayes: _initialize_db: SQL error: ".$self->{_dbh}->errstr()); |
703 |
dbg("bayes: _initialize_db: SQL error: ".$self->{_dbh}->errstr()); |
Lines 713-751
Link Here
|
713 |
|
713 |
|
714 |
my ($id) = $sthselect->fetchrow_array(); |
714 |
my ($id) = $sthselect->fetchrow_array(); |
715 |
|
715 |
|
716 |
if ($id) { |
716 |
unless ($id) { |
717 |
$self->{_userid} = $id; |
717 |
# For now let the database setup the other variables as defaults |
718 |
dbg("bayes: Using userid: ".$self->{_userid}); |
718 |
my $sqlinsert = "INSERT INTO bayes_vars (username) VALUES (?)"; |
719 |
$sthselect->finish(); |
719 |
|
720 |
return 1; |
720 |
my $rows = $self->{_dbh}->do($sqlinsert, |
721 |
} |
721 |
undef, |
722 |
|
722 |
$self->{_username}); |
723 |
# Do not create an entry for this user unless we were specifically asked to |
723 |
unless (defined($rows)) { |
724 |
return 0 unless ($create_entry_p); |
724 |
dbg("bayes: _initialize_db: SQL error: ".$self->{_dbh}->errstr()); |
|
|
725 |
$self->{_dbh}->rollback(); |
726 |
return 0; |
727 |
} |
725 |
|
728 |
|
726 |
# For now let the database setup the other variables as defaults |
729 |
$id = $self->{_dbh}->{'mysql_insertid'}; |
727 |
my $sqlinsert = "INSERT INTO bayes_vars (username) VALUES (?)"; |
|
|
728 |
|
730 |
|
729 |
my $rows = $self->{_dbh}->do($sqlinsert, |
731 |
$self->{_dbh}->commit(); |
730 |
undef, |
|
|
731 |
$self->{_username}); |
732 |
unless (defined($rows)) { |
733 |
dbg("bayes: _initialize_db: SQL error: ".$self->{_dbh}->errstr()); |
734 |
$self->{_dbh}->rollback(); |
735 |
return 0; |
736 |
} |
732 |
} |
737 |
|
733 |
|
738 |
$id = $self->{_dbh}->{'mysql_insertid'}; |
|
|
739 |
|
740 |
$self->{_dbh}->commit(); |
741 |
|
742 |
if ($id) { |
734 |
if ($id) { |
743 |
$self->{_userid} = $id; |
735 |
$self->{_userid} = $id; |
744 |
dbg("bayes: using userid: ".$self->{_userid}); |
736 |
dbg("bayes: Using userid: ".$self->{_userid}); |
745 |
return 1; |
737 |
return 1; |
746 |
} |
738 |
} |
747 |
|
739 |
else { |
748 |
return 1; |
740 |
dbg("bayes: _initialize_db: error: can't fetch userid"); |
|
|
741 |
return 0; |
742 |
} |
749 |
} |
743 |
} |
750 |
|
744 |
|
751 |
=head2 _put_token |
745 |
=head2 _put_token |