collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18363
  • stats Total Topics: 2500
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: PostgreSQL as an alternative to MySQL?  (Read 7504 times)

0 Members and 1 Guest are viewing this topic.

Offline TigerDragon

  • BeBot Rookie
  • *
  • Posts: 7
  • Karma: +0/-0
PostgreSQL as an alternative to MySQL?
« on: February 19, 2008, 02:55:45 am »
I'm considering diving into the source to add support for using PostgreSQL as an alternative database for those who prefer using it (like myself.)

This would require a new module similar to the MySQL.php file and code that allows for one or the other to be loaded (so the bot doesn't die if MySQL isn't there, but PostgreSQL most certainly is.)

Offline Blueeagle

  • Omnipotent
  • BeBot Hero
  • ******
  • Posts: 323
  • Karma: +0/-0
Re: PostgreSQL as an alternative to MySQL?
« Reply #1 on: February 19, 2008, 03:33:57 am »
A couple of thoughts here.

conf/Bot.conf should have a variable
$preferred_database = 'mysql'; //or 'postgre'

and Sources/Bot.php should read that variable and check if the server for $preferred_database is availible. It's debatable if it should die if the preferred database isn't running but the other is. For me that's a coin toss.

If all variables are present in conf/MySQL.php that should be renamed to conf/SQL.php. If the variables needed for either differ greatly creating a conf/PostgreSQL.php would be in order.

Table creation and schema handling would probably need abstracting if the syntax differ. In any case either ought to be abstracted to insure a uniform handling.

There's probably a host of other issues that need adressing but we'll take them as they come.

Welcome to BeBot and thank you for wanting to contribute to the development.
The only problem that can't be solved by adding another wrapper is having too many wrappers.

Offline TigerDragon

  • BeBot Rookie
  • *
  • Posts: 7
  • Karma: +0/-0
Re: PostgreSQL as an alternative to MySQL?
« Reply #2 on: February 19, 2008, 05:12:23 pm »
Okay, I've taken a cursory glance at the source for several .php files and I think your suggestion on IRC to encapsulate the "create table" calls in a separate function from "query" is probably best.  The reason I say this is... there are enough differences between MySQL and PostgreSQL to warrant it.  The easiest example to use is "auto_increment."  MySQL uses auto_increment to define a variable that automatically increases in value each time an insert is applied to the table.  PostgreSQL uses sequences instead.

I also want to encapsulate things like MYSQL_ASSOC into a variable, because the pgsql equivalent function uses PGSQL_ASSOC instead.

It's going to take some work to try to make the database functions transparent, but I think it will be worth it in the end (because it will make it easier for the next person to add support for their favorite SQL server!)

Offline Blueeagle

  • Omnipotent
  • BeBot Hero
  • ******
  • Posts: 323
  • Karma: +0/-0
Re: PostgreSQL as an alternative to MySQL?
« Reply #3 on: February 20, 2008, 07:53:16 am »
I also want to encapsulate things like MYSQL_ASSOC into a variable, because the pgsql equivalent function uses PGSQL_ASSOC instead.

I vote we return MYSQL_BOTH and PGSQL_BOTH at all times (provided that's an option for PGSQL). The only drawback I can see is if the array becomes too big a memory hog.

The alternative is to always return an associative array. That would be "a better way"(tm) imo.

The only problem that can't be solved by adding another wrapper is having too many wrappers.

Offline TigerDragon

  • BeBot Rookie
  • *
  • Posts: 7
  • Karma: +0/-0
Re: PostgreSQL as an alternative to MySQL?
« Reply #4 on: February 20, 2008, 03:49:20 pm »
The default return type for postgres is PGSQL_BOTH.  I haven't looked at the php functions for mysql to see what the default is for it, but I assume it's the same.

I don't like assuming default behavior, because it can change at any time in future updates to php.  This would potentially cause problems.  Returning BOTH doubles the size of the return array, but not every mysql query is calling ASSOC.  I haven't looked to see if only the "create table" calls are not doing this, but I think (from memory) that some of the regular select queries were not calling ASSOC, and thus there is some mixed behavior in the bot already.  I could be wrong, though.

Either changing it to be consistently ASSOC or changing it to use a wrapper variable as part of the encapsulating "SQL" object would work.

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Re: PostgreSQL as an alternative to MySQL?
« Reply #5 on: February 20, 2008, 03:59:29 pm »
Always using ASSOC would be the cleaner (and less error-prone) way.

I guess we are just too lazy to adapt every single case of the normal arrays - which are the default (I think...) due to historic reasons.

Offline TigerDragon

  • BeBot Rookie
  • *
  • Posts: 7
  • Karma: +0/-0
Re: PostgreSQL as an alternative to MySQL?
« Reply #6 on: February 20, 2008, 05:28:15 pm »
Then I'll look at making ASSOC be the "default" for the query function in the generic SQL wrapper class when I add the create() function for creating tables.

Offline Blueeagle

  • Omnipotent
  • BeBot Hero
  • ******
  • Posts: 323
  • Karma: +0/-0
Re: PostgreSQL as an alternative to MySQL?
« Reply #7 on: February 20, 2008, 05:47:00 pm »
...the normal arrays - which are the default (I think...) due to historic reasons.
I think that was one of my first contributions making MYSQL_ASSOC optional in the select()-function.

I really do not see any good reason to keep using numeric indexes from the queries.
The only problem that can't be solved by adding another wrapper is having too many wrappers.

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Re: PostgreSQL as an alternative to MySQL?
« Reply #8 on: February 20, 2008, 05:51:52 pm »
I really do not see any good reason to keep using numeric indexes from the queries.
It would require a thorough rewrite of every function using the numeric version...
I guess this is the main reason why it isn't changed.

Offline TigerDragon

  • BeBot Rookie
  • *
  • Posts: 7
  • Karma: +0/-0
Re: PostgreSQL as an alternative to MySQL?
« Reply #9 on: February 20, 2008, 07:08:43 pm »
I expect to be going a thorough re-write of a lot of functions.  Do you all mind if I clean up some of the comments, too?   Fix spelling errors, make all the files use the same formatting (some use spaces, others use tabs, for example) and other janitorial work while I'm doing this project?

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Re: PostgreSQL as an alternative to MySQL?
« Reply #10 on: February 20, 2008, 07:14:21 pm »
Feel free, if you create a patch file I'll most likely commit the changes to the SVN.

Changes to the trunk may create some conflicts, as I'm trying to get some work on the bot done the next days.
« Last Edit: February 20, 2008, 07:16:10 pm by Alreadythere »

Offline Glarawyn

  • BeBot Hero
  • ******
  • Posts: 521
  • Karma: +0/-0
Re: PostgreSQL as an alternative to MySQL?
« Reply #11 on: February 21, 2008, 01:35:37 am »
IMHO MYSQL_ASSOC should be default. There are cases where the numeric array makes more sense though. When I know a query is only going to return one result (or if it returns more than one result something is wrong!) I stick with the numeric index.

I vote for keeping the option to switch between numeric, associative, or both, but change the default to associative.

I don't thing MYSQL_BOTH would be a good idea. Too much possibility for errors and issues with modules iterating through the both the numeric index and associative indexes....

Offline TigerDragon

  • BeBot Rookie
  • *
  • Posts: 7
  • Karma: +0/-0
Re: PostgreSQL as an alternative to MySQL?
« Reply #12 on: February 21, 2008, 05:14:46 pm »
I'll hold off on this until a consensus is met.  Whatever the case, the "BOTH" or "ASSOC" needs encapsulation, because "MYSQL_BOTH" and "MYSQL_ASSOC" are for the mysql functions only.  The postgresql functions have their own "PGSQL_BOTH" and "PGSQL_ASSOC" and that is what should be used when the database is postgres instead of mysql.

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Re: PostgreSQL as an alternative to MySQL?
« Reply #13 on: February 21, 2008, 06:24:02 pm »
You could make an abstract base class for database access, and then make MySQL and PostgreSQL and perhaps any further dababase we use.

Then define abstract functions in the database class like get_assoc(), get_both(), get_number(), and the implementations return the valid MYSQL_ASSOC or PGSQL_ASSOC values as the database needs.

Offline TigerDragon

  • BeBot Rookie
  • *
  • Posts: 7
  • Karma: +0/-0
Re: PostgreSQL as an alternative to MySQL?
« Reply #14 on: February 21, 2008, 07:23:16 pm »
You could make an abstract base class for database access, and then make MySQL and PostgreSQL and perhaps any further dababase we use.

This is what I've meant when I've said "encapsulated."

Quote
Then define abstract functions in the database class like get_assoc(), get_both(), get_number(), and the implementations return the valid MYSQL_ASSOC or PGSQL_ASSOC values as the database needs.

Yep... pretty much what I was planning.

 

* Recent Posts
[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm]


0.8.x updates for AoC by bitnykk
[January 30, 2024, 11:16:08 pm]


0.8.x updates for AO by bitnykk
[January 30, 2024, 11:15:37 pm]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am]


Bebot and Rasberry by bitnykk
[November 29, 2023, 11:04:14 pm]

* Who's Online
  • Dot Guests: 665
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal