Code

Don't loose schema definition internally to allow easy re-creation of database.
authorjanw <janw@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 30 Mar 2009 10:05:36 +0000 (10:05 +0000)
committerjanw <janw@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 30 Mar 2009 10:05:36 +0000 (10:05 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@13569 594d385d-05f5-0310-b6e9-bd551577e9d8

trunk/gosa-si/modules/DBsqlite.pm

index 0a4f5d97c4808b2992e194ef2583880ef06569de..161f15413e741ae88b949e94999d754a589cb1e0 100644 (file)
@@ -15,7 +15,6 @@ sub new {
        my $class = shift;
        my $db_name = shift;
 
-       #my $lock = $db_name.".si.lock";
        my $lock = $db_name;
        my $self = {dbh=>undef,db_name=>undef,db_lock=>undef,db_lock_handle=>undef};
        my $dbh = DBI->connect("dbi:SQLite:dbname=$db_name", "", "", {RaiseError => 1, AutoCommit => 1, PrintError => 0});
@@ -86,16 +85,11 @@ sub create_table {
        my @col_names;
        my @col_names_creation;
        foreach my $col_name (@$col_names_ref) {
-               # Save full column description for creation of database
-               push(@col_names_creation, $col_name);
-               my @t = split(" ", $col_name);
-               my $column_name = $t[0];
-               # Save column name internally for select_dbentry
-               push(@col_names, $column_name);
+               push(@col_names, $col_name);
        }
        
        $col_names->{ $table_name } = \@col_names;
-       my $col_names_string = join(", ", @col_names_creation);
+       my $col_names_string = join(", ", @col_names);
        my $sql_statement = "CREATE TABLE IF NOT EXISTS $table_name ( $col_names_string )"; 
        my $res = $self->exec_statement($sql_statement);
        
@@ -270,15 +264,17 @@ sub get_table_columns {
        my @column_names;
 
        if(exists $col_names->{$table}) {
-               @column_names = @{$col_names->{$table}};
+               foreach my $col_name (@{$col_names->{$table}}) {
+                       push @column_names, ($1) if $col_name =~ /^(.*?)\s.*$/;
+               }
        } else {
                my @res;
                foreach my $column ( $self->exec_statement ( "pragma table_info('$table')" ) ) {
                        push(@column_names, @$column[1]);
                }
        }
-       return \@column_names;
 
+       return \@column_names;
 }