An unfinished system to manage all your paper documentation in an easy way.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

dev_cleanup_db.pl 910B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/perl
  2. use strict;
  3. use JSON;
  4. use DBI;
  5. use warnings;
  6. my $conf = load_conf("../etc/autodoc.json");
  7. my $dbh = sqlconnect($conf->{sql});
  8. my @del = (
  9. 'pages',
  10. 'documents',
  11. 'tags',
  12. 'words'
  13. );
  14. foreach ( @del ) {
  15. print "DELETE FROM $_\n";
  16. sqlquery($dbh, "DELETE FROM $_");
  17. }
  18. sub load_conf {
  19. my($file) = @_;
  20. my $x='';
  21. open(F,"$file") || fatal_api_error(500,"Failed to load configuration file");
  22. while(<F>) { $x.=$_; }
  23. close(F);
  24. return from_json($x);
  25. }
  26. sub sqlconnect {
  27. my($sql) = @_;
  28. my $dsn = "DBI:mysql:database=$sql->{base};host=$sql->{host}";
  29. my $dbh = DBI->connect($dsn, $sql->{user}, $sql->{pass}) || \\
  30. print STDERR "Failed to connect to database\n";
  31. return $dbh;
  32. }
  33. sub sqlquery {
  34. my $dbh = shift;
  35. my $query = shift;
  36. my @args = @_;
  37. my $sth = $dbh->prepare($query) || print STDERR $dbh->error();
  38. $sth->execute(@args) || print STDERR $sth->error();
  39. return $sth;
  40. }