Why is function JDatabase::replacePrefix() now suddenly protected ?

128 views
Skip to first unread message

Beat

unread,
Jul 27, 2011, 6:29:53 PM7/27/11
to Joomla! Framework Development
Now there is a protected in front of function replacePrefix :

abstract class JDatabase
{
protected function replacePrefix($sql, $prefix='#__')
}

This function was always part of the Joomla API.

Can it be made non-protected for the Joomla 1.7.1 release ?

Or is it definitievly depreciated ? In which case how to use it ?

Thanks,
Beat

Andrew Eddie

unread,
Jul 27, 2011, 6:41:20 PM7/27/11
to joomla-dev...@googlegroups.com
Hi Beat

It's still there - it's not deprecated. Looking back it was public in
1.5 but has been protected since 1.6.

What's your use case?

Regards,
Andrew Eddie
http://learn.theartofjoomla.com - training videos for Joomla 1.6 developers

> --
> You received this message because you are subscribed to the Google Groups "Joomla! Framework Development" group.
> To post to this group, send an email to joomla-dev...@googlegroups.com.
> To unsubscribe from this group, send email to joomla-dev-frame...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/joomla-dev-framework?hl=en-GB.
>
>

Beat

unread,
Jul 27, 2011, 7:54:31 PM7/27/11
to Joomla! Framework Development
Hi Andrew,

Sorry (and no worries ;) ), but in 1.6.5, it's public:

public function replacePrefix($sql, $prefix='#__')

We are using it to check database structure at install time and in
tools commands. So, if it would have become protected in J1.6, we
would have known fast about it. ;)


Our use case of this method that imho has no reason to be protected:


in a particular SQL statement that we use:

SHOW TABLE STATUS LIKE '#__xxxxxxx';

very logically, the normal query of Joomla won't replace the part in
the string, which is a correct behavior. That's why we need that
method public to be able to replace the table name within the SQL
string.

Hope that makes sense.

Just need to know what's happening in Joomla 1.7.1 (fixed to become
public or depreciated definitely in joomla 1.7).

Best Regards,
Beat


On Jul 28, 12:41 am, Andrew Eddie <mambob...@gmail.com> wrote:
> Hi Beat
>
> It's still there - it's not deprecated.  Looking back it was public in
> 1.5 but has been protected since 1.6.
>
> What's your use case?
>
> Regards,
> Andrew Eddiehttp://learn.theartofjoomla.com- training videos for Joomla 1.6 developers

Andrew Eddie

unread,
Jul 27, 2011, 8:01:04 PM7/27/11
to joomla-dev...@googlegroups.com
On 27 July 2011 16:54, Beat <bea...@gmail.com> wrote:
> Hi Andrew,
>
> Sorry (and no worries ;) ), but in 1.6.5, it's public:

Ok, I must have looked at the wrong file version.

> in a particular SQL statement that we use:
>
> SHOW TABLE STATUS LIKE '#__xxxxxxx';

In 1.7 I'd write that like:

$db = JFactory::getDbo();

$db->setQuery('SHOW TABLE STATUS LIKE '.
$db->q($db->getPrefix().'xxxxx')
);

I think that should work.

That will work fine in 1.5 too I think.

What do you think?

Regards,
Andrew Eddie
http://learn.theartofjoomla.com - training videos for Joomla 1.6 developers

Beat

unread,
Jul 27, 2011, 8:44:14 PM7/27/11
to Joomla! Framework Development
Hi Andew,

There are workarounds, no worries, I found getPrefix(), but it makes
us need to change our existing code, so it counts as another
incompatibility of Joomla 1.7. Actually '#__xxxxx' is a parameter of a
more complex function, so instead of what you suggested, we would need
to do something like a:

str_replace( $prefix, getPrefix(), $tableName )

instead, but as getPrefix() doesn't exist in all Joomla versions, we
need to check Joomla version, and call the appropriate method.

It's simply another (at first glance unneeded) sudden hidden backwards
incompatibility in the Joomla framework, making the move from Joomla
1.6 to 1.7 not that trivial for larger extensions. That's why I asked
if it's deprecated or maintained in the short-term future of 1.7.1.

From your reply, I guess that the answer is that you wish to deprecate
definitively the public use of replacePrefix() ?

May I ask in return in a friendly and constructive way what's the use-
case of making that method suddenly protected instead of public as
before (except of making extensions incompatible) ? ;-)

Best Regards,
Beat


On Jul 28, 2:01 am, Andrew Eddie <mambob...@gmail.com> wrote:
> On 27 July 2011 16:54, Beat <beat...@gmail.com> wrote:
>
> > Hi Andrew,
>
> > Sorry (and no worries ;) ), but in 1.6.5, it's public:
>
> Ok, I must have looked at the wrong file version.
>
> > in a particular SQL statement that we use:
>
> > SHOW TABLE STATUS LIKE '#__xxxxxxx';
>
> In 1.7 I'd write that like:
>
> $db = JFactory::getDbo();
>
> $db->setQuery('SHOW TABLE STATUS LIKE '.
>   $db->q($db->getPrefix().'xxxxx')
> );
>
> I think that should work.
>
> That will work fine in 1.5 too I think.
>
> What do you think?
>
> Regards,
> Andrew Eddiehttp://learn.theartofjoomla.com- training videos for Joomla 1.6 developers
>
>
>
>
>
> > very logically, the normal query of Joomla won't replace the part in
> > the string, which is a correct behavior. That's why we need that
> > method public to be able to replace the table name within the SQL
> > string.
>
> > Hope that makes sense.
>
> > Just need to know what's happening in Joomla 1.7.1 (fixed to become
> > public or depreciated definitely in joomla 1.7).
>
> > Best Regards,
> > Beat
>
> > On Jul 28, 12:41 am, Andrew Eddie <mambob...@gmail.com> wrote:
> >> Hi Beat
>
> >> It's still there - it's not deprecated.  Looking back it was public in
> >> 1.5 but has been protected since 1.6.
>
> >> What's your use case?
>
> >> Regards,
> >> Andrew Eddiehttp://learn.theartofjoomla.com-training videos for Joomla 1.6 developers

Nikolai Plath

unread,
Jul 27, 2011, 9:35:47 PM7/27/11
to Joomla! Framework Development
So why not making it public - like JDatabase::splitSql() which may
have similar use cases - i remember a custom app that used them both
to perform "query stuff". Both functions are neat and should be
available from the factory without extending JDatabase..

I also can not see the need to have it protected, as is does not
modify anything in the object.

But I am shure it has not been done to make extensions incompatible ;)

BTW: Of course "protected" has nothing to do with "deprecated" ;)
> > Andrew Eddiehttp://learn.theartofjoomla.com-training videos for Joomla 1.6 developers
>
> > > very logically, the normal query of Joomla won't replace the part in
> > > the string, which is a correct behavior. That's why we need that
> > > method public to be able to replace the table name within the SQL
> > > string.
>
> > > Hope that makes sense.
>
> > > Just need to know what's happening in Joomla 1.7.1 (fixed to become
> > > public or depreciated definitely in joomla 1.7).
>
> > > Best Regards,
> > > Beat
>
> > > On Jul 28, 12:41 am, Andrew Eddie <mambob...@gmail.com> wrote:
> > >> Hi Beat
>
> > >> It's still there - it's not deprecated.  Looking back it was public in
> > >> 1.5 but has been protected since 1.6.
>
> > >> What's your use case?
>
> > >> Regards,
> > >> Andrew Eddiehttp://learn.theartofjoomla.com-trainingvideos for Joomla 1.6 developers

Andrew Eddie

unread,
Jul 28, 2011, 1:25:47 AM7/28/11
to joomla-dev...@googlegroups.com
Hi Beat.

By all means, send a pull request for it. If that's what it was in
1.6, then for backward compatibility reasons we can change it back.
It's not a big deal and it's probably a 50/50 call on whether it
should be protected or not.

However, the code using getPrefix will work perfectly well in 1.5 as
well. getPrefix is there available so there is absolutely no
incompatibility. I can't recall if it exists in 1.0, but then I
probably am not concerned if it does or not :)

Regards,
Andrew Eddie
http://learn.theartofjoomla.com - training videos for Joomla 1.6 developers

Reply all
Reply to author
Forward
0 new messages