[Owncloud] Setup with PostgreSQL broken

Daniel Köb daniel.koeb at peony.at
Sat Dec 31 17:24:31 UTC 2011


Hi,

After getting the setup to detect PostgreSQL (see previous post), I ran
into the next problem with setting up ownCloud. I got a SQL error
message saying that the "users" table did not exist. And in fact, the
setup created the database but no tables at all.
I debugged into it and found that the code that should detect if the
database has to be filled with the required tables is wrong, in multiple
ways. Here is the corresponding snippet from lib/setup.php (lines 182ff)

  //fill the database if needed
  $query = "SELECT relname FROM pg_class WHERE \
relname='{$dbtableprefix}users' limit 1";
  $result = pg_query($connection, $query);
  if(!$result) {
    OC_DB::createDbFromStructure('db_structure.xml');
  }

First of all, pg_query does not return false if no matching record is
found; instead a valid result with zero rows is returned.
Second, the connection used for this query is not to ownCloud's database
but to the system database (postgres - check the connection string a few
lines before). This means that the result of this check has nothing to
do with ownCloud's database and can be anything.
Third, I don't understand this condition at all. The database was just
created a few lines before these, so who should have filled it anyway?
There is a possibility that the database existed already. But then it
still will be tried to create it again (will result in an error message)
and then this check makes more sense. But if this is intended, then
there should be an additional check if the database already exists...

I haven't provided a patch this time because I'm not sure what the
intended behavior is. (BTW: the same seems to be true for mysql)

Daniel





More information about the Owncloud mailing list