Let the DB Revolution Begin (MS SQL)

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
Souvent22's picture

Ok, so I finally got around to it. Drupal 5.0 (6.0-dev) MS SQL support. I am hoping this thread can be a sort of 'behind the scenes' working group with official patches posted to Drupal.org.


NOTE: This has been tested with:

  • PHP 5.1.6
  • SQL Server Standard 2005
  • ntwdblib.dll v. 2000.80.194.0 (you will need this updated version and not the one that comes with your php install)

With that said, on to the patch. It is definalty a hefty one at 51KB. So, a quick over-view of what it does.
First, a few files have been added:

  • install.mssql.inc
  • database.mssql.inc

Futher more, the install.inc file has been modified to include ms sql as an option so that the install script runs.

So, it's current status, it runs and creates the db nicely. But, there are some bugs to be had:

  • the system table for some reason has the status column set to 0 except for system.module for some reason
  • when an error happens, nothing it thrown back because the connection immediatley closes. perhaps we need to look at a better way to trap and handel errors. (the system just sits until execution timeout)
  • after manipulating the system table, i had to modify the blocks.module sql call because it calls a "distinct" on the page column (which is a text datatype) and throws an error cause mssql says its not comparable, so i took off the distinct modifier for now, and i'm investigating that SQL statement.

Ok, that's it for now. Hopefully this is a start. We at least have all the tools we need to work with right now to get this going.

Attached is the patch, and the ntwdblib.dll file that you will need to overwrite in your PHP directory.

Oh, almost forgot. When you set your db server location on install, MS, in its infinite wisdom, doesn't understand port specifications in the format localhost:1443. You have to use a comma like, localhost,1443. So, so specificy your port, include it in the db server textfield, and leave the "Port" textfield blank. Also, be sure you have TCP connections, and Windows Authentication + SQL Server authentication turned on, or you will never connect.

Also, I just realized, I can't attach dll files. So here's a link to get the file:

http://webzila.com/dll/1/ntwdblib.zip <- dll file

AttachmentSize
database_mssql_support.txt76.04 KB
install.inc_.txt21.35 KB
install.mssql_.inc_.txt6.44 KB

Comments

great work

moshe weitzman's picture

great news, earnest. thanks for keeping us posted ... be sure to get the quirks fixed up in drupal core, so that we can at least distribute this as a simple contrib package for drupal 6 (if not in core completely)

time to revisit

moshe weitzman's picture

looks like schema APi is going in. what patches to core are needed so this can be happily in Contrib? maybe time to freshen this patch against HEAD. hopefully earnest is available and interested.

Notes

Souvent22's picture

These are just some general notes I am making for myself because I have I'm too lazy to go get a new pen:

Current Bugs/Issues/Thoughts:

  • When using the devel module and there's an error in table creation, it doesn't seem to show up in watch dog. Look into this.
  • Double check the shcema. Blocks was missing the 'title' field.
  • Implement the DB Informatoin hook (not sure what it is) so that when someone views the 'status' page, they can view information about their SQL-Server
  • Implement (when you have time for it) some 'fun' features. Take advantage of features that SQL-Server has that MySQL/Pgsql does not. E.g. DB alerts, snmp, graphs, etc.
  • With devel module, when "re-install" is called, it doesn't call the install hooks?

What's the status of this

amariotti's picture

What's the status of this project?

Andrew (amariotti)

Note on errors

brink's picture

I realize this is sort of defunct right now, but for anyone needing to extend this functionality for a specific purpose, I give you this:

just a quick note on error messages: I see that mssql_get_last_message() is used for error reporting. That's fraught with peril, as this function will return non-error messages such as, "Changed context to table foo".

There's a function I found on php.net that seems to work fairly reasonably well for php + sql server error messages. Can't find the comment that had it, so I'll paste the version I have handy (which is sort of a hack). Also note that this solution is sort of fraught with issues in that I don't believe it handles concurrency very well.

function mssql_error ($con = null) {
   if (!$con) {
     global $active_db;
     $con = $active_db;
     if (!$con) {
      return mssql_get_last_message();
     }
   }
    $sql    = "select @@ERROR as code";
    $result = mssql_query($sql, $con);
    $row    = mssql_fetch_array($result);
    $code  = $row["code"]; // error code
    if ($code) {
      $sql    = "select cast (description as varchar(255)) as errtxt from master.dbo.sysmessages where error = $code";
      $result = mssql_query($sql, $con);
      $row    = mssql_fetch_array($result);
   
      if ($row)
        $text  = $row["errtxt"]; // error text (with placeholders)
      else
        return "Code: ". $code;
    }
}

question

marco.zanca's picture

Hi there, it's the link to the dll broken? There is any other source to download it?
And, btw, it's this the only way for use ms-sql?

regards
Marco

mssql file missing

feloniusb's picture

Hey guys, where do I get this file from; database.mssql.inc ?

Enterprise

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: