I am working on making this module compatible with SQL Server. The last thing not working is the Select from DB area where it pulls tables and columns from the DB into select lists. SQL Server doesn't have a function like "SHOW TABLES" or "SHOW COLUMNS" so I adjusted that and pulls that data fine, however, I don't understand what the purpose of $db_tables is in this code for cck_address.module around line 212:

$results = db_query($sql);
global $db_url;
$db_name = substr(strrchr($db_url, "/"), 1);
$db_tables = 'Tables_in_' .$db_name;
while ($result = db_fetch_object($results)) {
  $all_tables[$result->$db_tables] = $result->$db_tables;
}

I can make this code work for me if I change $db_name to just "name":

$results = db_query($sql);
global $db_url;
$db_name = substr(strrchr($db_url, "/"), 1);
$db_tables = 'Tables_in_' .$db_name;
while ($result = db_fetch_object($results)) {
  $all_tables[$result->name] = $result->name;
}

Similarly, I "Field" wasn't working for me around line 1373:

  $results = db_query($sql, $array);
  while ($result = db_fetch_object($results)) {
    $column_options[$result->Field] = $result->Field;
  }

I needed to change "Field" to "name" to work:

  $results = db_query($sql, $array);
  while ($result = db_fetch_object($results)) {
    $column_options[$result->name] = $result->name;
  }

Do you think this is a SQL Server-specific issue or can you replicate this with other DBs?

Aside from this, I think I have everything working and will submit a patch soon for the few that may need this with a SQL Server DB.

CommentFileSizeAuthor
#3 cck_address.module-mssql.patch2.36 KBpcorbett
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rconstantine’s picture

$db_tables is just one of those weird things that when you print the object to the screen in order to find out where the data you want is, it is in a strange place. It would appear that every table had its own name inside a field called 'Tables_in_[database name]'. Don't ask me why, but it works for MySQL. SO if your changes work for you, they are probably fine. Same goes with your other change. When I code this junk, I have no foreknowledge of the data structures I'm using. I just print to screen at each step to see how things are and then go from there.

I would hope that any patch you might create would include a check of a global variable to determine which database is in use and then conditionally execute your code or mine. Since MySQL is by far the more common in use in the Drupal world, it should be the default. In other words "if the db is SQL Server, execute your code, else execute mine".

rconstantine’s picture

Status: Active » Postponed (maintainer needs more info)

I would like it if you have added full SQL Server support to this module that you post a patch so that I can review it for possible incorporation into this module. If you don't want to contribute that, please close this issue. If I haven't heard back from you here in a couple of weeks, I'll close it myself.

pcorbett’s picture

I was having trouble creating the patch due to line ending mismatches, but I think I've cleared everything up now. Here's the patch to make cck_address work on a SQL Server 2000 DB - slight adjustments will need to be made in the case someone is using SQL Server 2005/2008.

rconstantine’s picture

Status: Postponed (maintainer needs more info) » Needs review

Great! Thanks for the work. Do you know how hard it is to get people to send in patches?