Monday, November 10, 2014

Getting a list of tables in GnuCash

Here's some perl code to show a list of tables in a GnuCash file:

#!/usr/bin/env perl
# regc.pl - Reverse Engineer GnuCash

use strict;
use warnings;
use 5.10.0;
use DBI;
use Data::Dumper;

# Global Variables
my $gc_file = 'empty.gnucash';
my $dbh = DBI->connect("dbi:SQLite:dbname=$gc_file","","");

say Dumper tables($gc_file);

sub tables {
    my $file = shift;
    my $tables = [];

    my $res = `echo .schema | sqlite3 $file`;
    foreach my $t (split /;/, $res) {
        next unless $t =~ /CREATE TABLE (.*) \(/;
        push @{$tables}, $1;
    }
   
    return $tables;
}
 The list of tables are:

          'gnclock',
          'versions',
          'accounts',
          'books',
          'budgets',
          'budget_amounts',
          'commodities',
          'lots',
          'prices',
          'schedxactions',
          'transactions',
          'splits',
          'billterms',
          'customers',
          'employees',
          'entries',
          'invoices',
          'jobs',
          'orders',
          'taxtables',
          'taxtable_entries',
          'vendors',
          'recurrences',
          'slots'

No comments:

Post a Comment