From: janw Date: Thu, 12 Mar 2009 10:44:09 +0000 (+0000) Subject: Allow optional indices on table. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=34b2cd0f002d2485b725bd402c87e6737968b275;p=gosa.git Allow optional indices on table. git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@13535 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/trunk/gosa-si/modules/DBsqlite.pm b/trunk/gosa-si/modules/DBsqlite.pm index 60f864a71..d88f0e547 100644 --- a/trunk/gosa-si/modules/DBsqlite.pm +++ b/trunk/gosa-si/modules/DBsqlite.pm @@ -82,6 +82,7 @@ sub create_table { } my $table_name = shift; my $col_names_ref = shift; + my $index_names_ref = shift || undef; my @col_names; my @col_names_creation; foreach my $col_name (@$col_names_ref) { @@ -97,6 +98,14 @@ sub create_table { my $col_names_string = join(", ", @col_names_creation); my $sql_statement = "CREATE TABLE IF NOT EXISTS $table_name ( $col_names_string )"; my $res = $self->exec_statement($sql_statement); + + # Add indices + if(defined($index_names_ref) and ref($index_names_ref) eq 'ARRAY') { + foreach my $index_name (@$index_names_ref) { + $self->exec_statement("CREATE ".(($index_name eq 'id')?'UNIQUE':'')." INDEX IF NOT EXISTS $index_name on $table_name ($index_name);"); + } + } + return 0; }