Jump to content
Latest News: (loading..)
Kolingua

Discussion about Hard Coded Database Tables

Recommended Posts

They

 

@@whodah

 

/includes/filenames.php and /includes/database_tables.php are deprecated.

 

So the table references and file names are being hard coded on a going forward basis.

 

Dan

 

They are not deprecated yet, and probably causing a lot of confusion. filenames.php and database_tables.php should either be continued to be used, or removed entirely from the project.

Share this post


Link to post
Share on other sites

@@Dan Cole

 

I did a similar or same comment a while back and then people told the same thing as Ashley just did. They are not deprecated yet.

I have been told that I should avoid to use TABLE_ or FILENAME_ in future codes or addons.

filenames.php and database_tables.php are still in use in current osC version (official and unofficial releases).

 

I guess in the next or next, next release of osC things will be different but till then...

Edited by Tsimi

Share this post


Link to post
Share on other sites

For my clarification - when you say "Depreciated" are you meaning that they will not be used in future versions of OSC or that their use/function is actually going to be depreciated in some version of PHP?

 

If the former then depreciated is not a good name - maybe redundant would be better?


Now running on a fully modded, Mobile Friendly 2.3.4 Store with the Excellent MTS installed - See my profile for the mods installed ..... So much thanks for all the help given along the way by forum members.

Share this post


Link to post
Share on other sites

I am not sure but for the currently version to 2.3.9, I don't think.

The code in 2.4 is very different and all TABLE_ of FILENAME_ has been removed for example.

The best is to look the 2.4

Edited by Gyakutsuki


Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

Tuto for 2.4 :
- How to Display a new page with app
- How to make Header Tags under app APP
- How to make a
boostrap modal with external element
 

 

Share this post


Link to post
Share on other sites

Deprecate https://en.wikipedia.org/wiki/Deprecation

 

The two files:

/includes/database_tables.php

/includes/filenames.php

 

are gone. They no longer exist in v2.4

 

Get used to a different style of coding now...to help yourselves in the future.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites

Personally, I like the idea especially with the table names and it's easier write without all the concatenation.  You can test or experiment in something like phpmyadmin easier with this too. 

 

I also get Burt's points about only a few helping.  I don't have a lot of patience or attention span for a lot of what happens on this forum, so I choose to be a community sponsor.  Hopefully, that helps.

Edited by John W

I'm not really a dog.

Share this post


Link to post
Share on other sites

@@John W being a sponsor does help, thank you


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites

I don't have a lot of patience or attention span for a lot of what happens on this forum

 

I understand your pain  :-


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites
Hello,

 

My apologies, I did not realize database_tables.php was being depreciated until my posts above were moved from another thread into this one. Sorry about that!

 

Does this mean that those wishing to do table prefixes will be doing it 'by hand' so to speak? Food for thought: I personally like to see all of my wordpress tables together, OSC tables together, gallery tables together, etc. etc. (via prefixes) for both ease of human-reading and to avoid table name conflicts with another package in the same database. I don't mean to stir the pot, just to mention it in case something clicks down the road. And while we may have different opinions, I fully respect the programming team's decision(s).

 

Thanks for all your hard work,

-Who Dah?

Share this post


Link to post
Share on other sites

One downside to the database tables change is it may/will make it harder to do a file comparison when looking for changes in new versions.  I use Beyond Compare, which I love.  Obviously, going through each file and doing individual search and replace would be time consuming as hell.  Hell is bad.  I have a tool called RegexBuddy that can do all kinds of stuff wiht regex including testing.  Using that tool I created this regex, which probably needs tweeking and may not be perfect.

This regex finds for instance TABLE_PRODUCTS_DESCRIPTION and captures PRODUCTS_DESCRIPTION, then the replacement replaces PRODUCTS_DESCRIPTION with products_description lower cased.

"\s?\. TABLE_([A-Z_]+) \.\s?"

with the replacement

\L1

Using RegexBuddy I did a test grep on the boxes folder and it seems to have worked perfectly replacing all the table names on my initial test.  I test this on my local test site and then look for errors.


I'm not really a dog.

Share this post


Link to post
Share on other sites

To me one big advantage of the having table names directly is you can format it to make it easier to read.  I personally find the 4000 character or more lines annoying and harder to compare.  You can format sql using new versions of phpmyadmin to format like below.  Food for thought.

          SELECT DISTINCT
            p.products_id,
            pd.products_name
          FROM
            products p,
            products_description pd
          WHERE
            p.products_status = '1' AND p.products_ordered > 0 AND p.products_id = pd.products_id AND pd.language_id = '" . (int) $languages_id . "'
          ORDER BY
            p.products_ordered DESC,
            pd.products_name
          LIMIT " . MAX_DISPLAY_BESTSELLERS);

I'm not really a dog.

Share this post


Link to post
Share on other sites

I probably didn't explain my regex post well enough.  Basically, the line below will go from

$best_sellers_query = tep_db_query("select distinct p.products_id, pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and '" . (int)$current_category_id . "' in (c.categories_id, c.parent_id) order by p.products_ordered desc, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS);

to

$best_sellers_query = tep_db_query("select distinct p.products_id, pd.products_name from products p, products_description pd, products_to_categories p2c, categories c where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and '" . (int)$current_category_id . "' in (c.categories_id, c.parent_id) order by p.products_ordered desc, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS);

with a click of a button. 


I'm not really a dog.

Share this post


Link to post
Share on other sites

OK, some hosting accounts are limited to one database, so if you want osC in addition to another application, you have to be careful that your table names (all in the same database) don't collide. The easiest way to do this is with a prefix, such as osc_. Now, if your table names are hard coded (inline) everywhere, you have to look at every possible place that a table name is mentioned, and change it there. That, instead of changing it one database_tables.php file. A one time job, you say? How about if you want to run two copies of osC, such as a production and a development copy with osc1_ and osc2_? You have to do it again. Use global search and replace, such as the sed utility? OK, instead of "TABLE_PRODUCTS" you have "products". How do you easily keep from hitting an innocent text string in a comment or message, rather than just where it's used as a table name? I suspect that those clamoring for table names to be inlined for clean code, simply haven't thought it through all the way.

 

On the other hand, I can't think of any legitimate reason a user would need to change file names, so inlining file names is probably harmless. Examples of harm are welcome.


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get (stable) Frozen or (unstable) Edge. See also the naming convention and the latest community-supported responsive "Edge" release

Share this post


Link to post
Share on other sites

The "upcoming" OSC V2.4 have a neat auto "prefix" functionality which works just fine with hard coded table names.

Share this post


Link to post
Share on other sites

One downside to the database tables change is it may/will make it harder to do a file comparison when looking for changes in new versions.  I use Beyond Compare, which I love.  Obviously, going through each file and doing individual search and replace would be time consuming as hell.  Hell is bad.  I have a tool called RegexBuddy that can do all kinds of stuff wiht regex including testing.  Using that tool I created this regex, which probably needs tweeking and may not be perfect.

This regex finds for instance TABLE_PRODUCTS_DESCRIPTION and captures PRODUCTS_DESCRIPTION, then the replacement replaces PRODUCTS_DESCRIPTION with products_description lower cased.

"\s?\. TABLE_([A-Z_]+) \.\s?"

with the replacement

\L1

Using RegexBuddy I did a test grep on the boxes folder and it seems to have worked perfectly replacing all the table names on my initial test.  I test this on my local test site and then look for errors.

 

Awesome. I've been using WinMerge. But I'm tucking this bit 'o knowledge away for the future - thanks!

 

The "upcoming" OSC V2.4 have a neat auto "prefix" functionality which works just fine with hard coded table names.

 

Nice! Best news I've heard all week. :)

Share this post


Link to post
Share on other sites

The "upcoming" OSC V2.4 have a neat auto "prefix" functionality which works just fine with hard coded table names.

 

Interesting. Can you elaborate on how this is supposed to work? I assume it means that any ad-hoc hard-coded queries will fail to be updated on the fly, and only those going through a "proper" glue layer will get the desired prefix (hello, broken add-ons). I'm wondering how that is any improvement in readability and execution speed over TABLE_* constants in code (yes, they need to be looked up and substituted too).

 

If it's a clean way to add a prefix to all osC tables, that might be usable, although I can think of cases where you might want to prefix only selected tables (e.g., while testing a change where you have a different table structure, and want to preserve the old one for possible reuse). Any thoughts on this?


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get (stable) Frozen or (unstable) Edge. See also the naming convention and the latest community-supported responsive "Edge" release

Share this post


Link to post
Share on other sites

 

To me one big advantage of the having table names directly is you can format it to make it easier to read.  I personally find the 4000 character or more lines annoying and harder to compare.  You can format sql using new versions of phpmyadmin to format like below.  Food for thought.

          SELECT DISTINCT
            p.products_id,
            pd.products_name
          FROM
            products p,
            products_description pd
          WHERE
            p.products_status = '1' AND p.products_ordered > 0 AND p.products_id = pd.products_id AND pd.language_id = '" . (int) $languages_id . "'
          ORDER BY
            p.products_ordered DESC,
            pd.products_name
          LIMIT " . MAX_DISPLAY_BESTSELLERS);

 

Something like

    SELECT DISTINCT
      p.products_id,
      pd.products_name
    FROM
      ". TABLE_PRODUCTS . " p,
      ". TABLE_PRODUCTS_DESCRIPTION . " pd
    WHERE
      p.products_status = '1' AND 
      p.products_ordered > 0 AND 
      p.products_id = pd.products_id AND 
      pd.language_id = '" . (int) $languages_id . "'
    ORDER BY
      p.products_ordered DESC,
      pd.products_name
    LIMIT " . MAX_DISPLAY_BESTSELLERS);

can't be done with defined names?


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get (stable) Frozen or (unstable) Edge. See also the naming convention and the latest community-supported responsive "Edge" release

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×