#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
use DBI;
use Data::Dumper;

my @cols = qw{share_id share_name share_owner share_flags perm_creator perm_default perm_guest attribute_name attribute_desc attribute_params share_parents} ;

my $sqlite_dbh = DBI->connect(
    "DBI:SQLite:test.sqlite",
    "", # No User
    "", # No Password
    {RaiseError => 1, AutoCommit => 1, sqlite_unicode => 1}
) or die $DBI::errstr;

my $date="2013_10_08";
my $create = qq{
    CREATE TABLE IF NOT EXISTS turba_shares_$date (
        share_id int(10) NOT NULL, AUTO_INCREMENT
        share_name varchar(255) NOT NULL,
        share_owner varchar(255) NOT NULL,
        share_flags int(11) NOT NULL DEFAULT '0',
        perm_creator int(11) NOT NULL DEFAULT '0',
        perm_default int(11) NOT NULL DEFAULT '0',
        perm_guest int(11) NOT NULL DEFAULT '0',
        attribute_name varchar(255) NOT NULL,
        attribute_desc varchar(255) DEFAULT NULL,
        attribute_params text,
        share_parents text,
        PRIMARY KEY (share_id)
    );
};

my $sqlite_insert = sprintf(
                             "INSERT INTO %s (%s) VALUES (%s);", 
                             "turba_shares_$date", 
                              join(", ", @cols ), 
                              join(", ", map { "?" } @cols )
                           );

#my $sqlite_insert = q{INSERT INTO turba_shares_2013_10_08 (share_id, share_name, share_owner, share_flags, perm_creator, perm_default, perm_guest, attribute_name, attribute_desc, attribute_params, share_parents) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);};
#my $sqlite_insert = q{INSERT INTO turba_shares_2013_10_08 (share_id, share_owner, share_flags, perm_creator, perm_default, perm_guest, attribute_name, attribute_desc, attribute_params, share_parents) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);};

say $sqlite_insert;

my $sqlite_sth=$sqlite_dbh->prepare($create);
$sqlite_sth->execute;
$sqlite_sth=$sqlite_dbh->prepare($sqlite_insert);
$sqlite_sth->finish;
