Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

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.

Link to comment
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...

Link to comment
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.

Link to comment
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


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

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

 

Link to comment
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.

I'm not really a dog.

Link to comment
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?

Link to comment
Share on other sites

  • 1 month later...

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.

Link to comment
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.

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

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

Link to comment
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. :)

Link to comment
Share on other sites

  • 9 months later...

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?

Link to comment
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?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...