An unfinished system to manage all your paper documentation in an easy way.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 5 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package Autodoc;
  2. use strict;
  3. use JSON;
  4. use DBI;
  5. use warnings 'all';
  6. use Exporter 'import';
  7. our @EXPORT = qw(sqlconnect sqlquery load_conf);
  8. sub load_conf {
  9. my($file) = @_;
  10. my $x='';
  11. die "No configuration file given" if !defined $file;
  12. open(F,"$file") || die "Failed to load configuration file";
  13. while(<F>) { $x.=$_; }
  14. close(F);
  15. return from_json($x);
  16. }
  17. sub sqlconnect {
  18. my($sql) = @_;
  19. my $dsn = "DBI:mysql:database=$sql->{base};host=$sql->{host}";
  20. my $dbh = DBI->connect($dsn, $sql->{user}, $sql->{pass}, {
  21. mysql_enable_utf8 => 1
  22. }) || die "Failed to connect to database";
  23. return $dbh;
  24. }
  25. sub sqlquery {
  26. my $dbh = shift;
  27. my $query = shift;
  28. my @args = @_;
  29. #print STDERR "$query\n";
  30. my $sth = $dbh->prepare($query) || die "Failed to execute SQL query";
  31. $sth->execute(@args) || die "Failed to execute SQL query";
  32. return $sth;
  33. }
  34. return 1;