1 package SGN
::Role
::Site
::DBIC
;
5 use namespace
::autoclean
;
9 use Class
::Load
':all';
13 'ensure_dbh_search_path_is_set',
19 Usage: my $schema = $c->dbic_schema( 'Schema::Package', 'connection_name' );
20 Desc : get a L<DBIx::Class::Schema> with the proper connection
21 parameters for the given connection name
22 Args : L<DBIx::Class> schema package name,
23 (optional) connection name to use
25 Side Effects: dies on failure
30 my ( $class, $schema_name, $profile_name, $sp_person_id) = @_;
32 print STDERR
"sp_person_id passed to DBIC Schema: $sp_person_id \n";
33 $class = ref $class if ref $class;
34 $schema_name or croak
"must provide a schema package name to dbic_schema";
35 #Class::MOP::load_class( $schema_name );
36 load_class
( $schema_name );
39 return $schema_cache{$class}{$profile_name || ''}{$schema_name} ||= do {
40 my $profile = $class->dbc_profile( $profile_name );
41 #print STDERR "profile: ".Dumper($profile)."\n";
42 #my $sp_person_id = $profile -> user -> get_object() -> get_sp_person_id;
43 $schema_name->connect(
44 @
{$profile}{qw
| dsn user password attributes
|},
45 { on_connect_call
=> sub { $class->ensure_dbh_search_path_is_set(my $dbh = shift->dbh ) ;
48 #my $delete_old_table_query = "DROP TABLE IF EXISTS logged_in_user";
49 #my $delete = $dbh -> do($delete_old_table_query);
50 my $q = "CREATE temporary table IF NOT EXISTS logged_in_user (sp_person_id bigint)";
51 my $create_handle = $dbh -> do($q);
52 #my $count_q = "select count(*) from logged_in_user";
53 #my $count_h = $dbh -> prepare($count_q);
54 #$count_h -> execute();
55 #my ($count) = $count_h->fetchrow_array();
56 #print STDERR "count: $count \n";
57 my $insert_query = "INSERT INTO logged_in_user (sp_person_id) VALUES (?)";
58 my $insert_handle = $dbh -> prepare
($insert_query);
59 $insert_handle -> execute
($sp_person_id);
67 # "CREATE temporary table IF NOT EXISTS logged_in_user (sp_person_id bigint)",
68 # "INSERT INTO logged_in_user (sp_person_id) VALUES ($sp_person_id)",
79 #my $dbh = $class->dbc->dbh;
80 #$dbh->do("CREATE temporary table IF NOT EXISTS logged_in_user (sp_person_id bigint)");
81 #my $insert_query = "INSERT INTO logged_in_user (sp_person_id) VALUES (?)";
82 #my $insert_handle = $dbh->prepare($insert_query);
83 #my $sp_person_id = $class -> user -> get_object() -> get_sp_person_id;
84 #$insert_handle->execute($sp_person_id);