Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

SELECT FROM Databasename without prefix

Quote Reply
SELECT FROM Databasename without prefix
I would like to fetch data from another table. Normally this is no problem, i know how to do it.
But this time i have no prefix for the table.

I have mLinks and mCategory but "Table"

When i use my usual selects inside a global i cant select from Table, only from mTable.
Is there a trick maybe to get rid of the prefix?

Last edited by:

Robert: Apr 21, 2017, 3:55 AM
Quote Reply
Re: [Robert] SELECT FROM Databasename without prefix In reply to
Got it:

GT/SQL/Table.pm

sub name {
# -----------------------------------------------------------
# $obj->name;
# -----------
# Returns the name of the current table instance.
#
# $obj->name($table_name);
# -------------------------
# Sets the name for the table to create.
#
my $self = shift;
if (defined $_[0]) {
my $name = shift;
my $prefix = $self->{connect}->{PREFIX};
if (length $prefix) {
unless ($name =~ /^$prefix/) {
$name = $prefix . $name;
}
}
unless ($name =~ /^(\w+)$/) {
return $self->fatal(BADNAME => $name);
}
$self->{name} = $1;

# If a schema exists, a new GT::Config object is needed as the name just changed
$self->_new_schema if $self->{schema};
}

if ($self->{name} eq 'mTableX') {
$self->{name} = 'TableX';
}

return $self->{name};
}
Quote Reply
Re: [Robert] SELECT FROM Databasename without prefix In reply to
Depending on what you want to do (i.e how complex), just do:

Code:
my $sth = $DB->table("Links")->do_query(qq|SELECT foo FROM Bar"|);

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] SELECT FROM Databasename without prefix In reply to
Thank you.
The point was the table itself.
I have a new table but without the prefix used.

I have mCategory and mLinks, but xNewTable.
To get data from this table, it needs the name correction in the pm like written above.
Quote Reply
Re: [Robert] SELECT FROM Databasename without prefix In reply to
Code:
my $sth = $DB->table("Links")->do_query(qq|SELECT foo FROM xNewTable|);

would work fine Whistle (you just wouldn't get the advantage of binding the variables, to make it safe from SQL injections)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] SELECT FROM Databasename without prefix In reply to
I can use

my $sth = $DB->table("New_Table_Name_without_prefix")->do_query(qq|SELECT foo FROM xNewTable|);

?
Quote Reply
Re: [Robert] SELECT FROM Databasename without prefix In reply to
No - but you don't need to. You just need to pass in a valid table (with the prefix), and then, whatever SQL you want:

Code:
my $sth = $DB->table("Links")->do_query(qq|SELECT foo FROM New_Table_Name_without_prefix|);

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] SELECT FROM Databasename without prefix In reply to
But why there is a Table Links?
Quote Reply
Re: [Robert] SELECT FROM Databasename without prefix In reply to
That is just so you can create a database object :) It could be any table name (Links, CatLinks, Changes, Users, whatever), and then you just pass along the SQL you want to run (as I said, you only want to do this when you don't care about sensitization, as it won't "bind" the variables, so someone could try to do SQL Injection if you accepted user input.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!