Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SAP Adaptive Server Enterprise database vendor #2347

Closed
wants to merge 2 commits into from

Conversation

Deltachaos
Copy link
Contributor

This PR adds the driver and DBAL for SAP Sybase Adaptive Server Enterprise databases. It distinguishes between versions 12.5 and below (base ASEPlatform), 15.0 (ASE150Platform), 15.5 (ASE155Platform), 15.7 (ASE157Platform), and 16.0 (ASE160Platform), similar to Microsoft SQL Server.
Because Microsoft SQL Server originally where the same product and then later have diverged i have oriented myself at the Microsoft SQL Server platform. A bit of the code could be copied over one by one, some other is only slightly different and even other is completely different.
The differences are most in the system tables, the basic SQL syntax is the same.

I had to move the conversion for date and time into the platform as well because in Sybase ASE the dates have the same string length every time. For example the date Jan 1 2012 and Jan 10 2012. Both have the same length, for the date with the one digit day there is a space in front (GitHub trim's multiple spaces here). This is something where we are not able to represent such a logic only with the PHP date format methods anymore. We need advanced logic to add this additional space if needed.
Another problem with the date and time handling is that the sybase_ct driver only returns dates and times with the precision of minutes and not with seconds (even if ASE can store date times up to milliseconds precision).
The tests are not able to handle this as well. Therefore, i have adjusted them to handle this case correctly.

Currently only a driver for the sybase_ct extension is implemented. There is a PDO driver DBLib available that is currently already used by the PDOSqlsrv as well. This PDO driver can also be used to connect to a ASE server.

There are currently some TODO's on my list:

  • Adding a implementation of the PDO DBLib driver for ASE as well (may this would solve the problem with the datetime precision).
  • Implementing the getAlterTableSQL method in the platform
  • Writing more tests for the platform itself

There are two other PR's related to this PR in other doctrine packages:

I hope this addition is appreciated and any feedback/help on the above issues would be welcomed.

@Deltachaos
Copy link
Contributor Author

I see there are problems with the DateTime conversion on travis now. I will fix them soon.

@kimhemsoe
Copy link
Member

Guessing this is still very much work in progress.

A few advice's:
Avoid using protected members and methods if not strictly needed.
Avoid changing existing tests.
Avoid changing types in a way that can result in BC breakage.

Ping us when you have something ready and again i have no idea if this have a chance to get merged anytime soon if ever.
You are ofc very much welcome to maintain it your own branch like is currently happening in #910

@Deltachaos
Copy link
Contributor Author

Hi @kimhemsoe,

first of all thanks for your response. I will adopt your suggestions step by step.
Yes there is a bit of stuff to do to get this thing ready. But i also have done some changes in this Pull Request that i think make sense anyway to get the dbal more platform agnostic. Especially the changes for the DateTime stuff i have done are important because you cannot asume that the date format that is specified in the tests is compatible with all relational databases.

So what i am now doing is to extract changes that are sensible even without the ASE driver to seperate Pull Requests. This has some advantages:

  1. We can discuss about the changes more purposeful
  2. The impact to the project is smaller if we only merge small pieces of code
  3. The PR's will probably being merged faster
  4. This PR gets easier maintainable because there is less touched code left over and therefore fewer conflicts will occur

I will reference the pull requests i open up in this PR.

I hope this approach is ok for you as well.

@kimhemsoe
Copy link
Member

yes that is ok with me.

@Deltachaos
Copy link
Contributor Author

Deltachaos commented Apr 18, 2016

@kimhemsoe @Ocramius This PR is now a bit more polished. It is now based on all the PR's i have separated from this PR so that diffs that are caused by the other PR's should disappear step by step if the other PR's are getting merged. In now only adds the commit 72478b1 on top of the other PR's and as you can see, this commit does not touches the tests (with tree execptions) anymore.

I still will add some more tests to the functionality of the ASE driver and add the alterTable method in the platform. But till this any feedback on the other PR's and of cause this one is welcome.

@Deltachaos
Copy link
Contributor Author

Year! At least the tests are not failing anymore!

@gnascimento
Copy link

Hello, Deltachaos!
You saved me a lot of work.
I want to test this driver and collaborate if it's needed. I'm working with Sybase, and I thought that I would write the whole Driver.

It's my first time on GitHub, sincerely. How can I do?

@Deltachaos
Copy link
Contributor Author

Deltachaos commented Sep 14, 2016

Hi @gnascimento

Nice to hear that you are interested in working with this driver. First of all you should force composer to use the correct doctrine packages. We are using this composer.json to do it:

{
  "require": {
      "doctrine/orm": "dev-ase-support as 2.4.0-dev",
      "doctrine/dbal": "dev-add-ase-platform as 2.5.0-dev",
      "doctrine/doctrine-bundle": "dev-ase as 1.4.0-dev"
  },
  "repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/Deltachaos/dbal.git"
    },
    {
        "type": "vcs",
        "url": "https://github.com/Deltachaos/DoctrineBundle.git"
    },
    {
        "type": "vcs",
        "url": "https://github.com/Deltachaos/doctrine2.git"
    }
  ]
}

The branches i have specified here are based on a stable doctrine version. This PR is based on the latest master of doctrine.
If you are using Symfony you should also use the doctrine/doctrine-bundle as specified here in the composer.json, if not it depends on which framework you are using.
If you are using symfony you can configure your database connection in the config.yml like this:

doctrine:
    dbal:
        driver:   ase
        host:     name-specified-in-interfaces-file
        dbname:   dbname
        user:     dbuser
        password: dbpassword

Please note that the driver is currently based on http://php.net/manual/en/book.sybase.php. Therefore, you should have a working installation of this extension on your server. It requires to have proper SYBASE_OCS, SYBASE and LD_LIBRARY_PATH environment variables set to work. Also, the host is in this case an alias to the entry of ${SYBASE}/interfaces

I started to create a driver using http://php.net/manual/de/ref.pdo-dblib.php but was not able to create a test server yet. If you would like to test it you can configure it like this:

doctrine:
    dbal:
        driver:   pdo_ase
        host:     server-address
        dbname:   dbname
        user:     dbuser
        password: dbpassword

But it will probably not work. If you have issues with this you can try to fix them in these classes Doctrine\DBAL\Driver\PDOASE\Driver and Doctrine\DBAL\Driver\PDOASE\Connection.
You should then have a look into the other PDO driver implementations like Doctrine\DBAL\Driver\PDOSqlsrv\Connection.

Please note: Doctrine DBAL is split into two parts.

  • Drivers: Establish a DB connection and provide a PDO like interface (even for non PDO based database extensions like oci8 or mysqli)
  • Platforms: Implement the database specific SQL dialect and tell which features are supported.

The driver and platform were currently only tested on a Solaris 11 zone. As soon as you have configured doctrine to work with this driver you can work with doctrine like with any other driver that doctrine supports. One thing that is currently not supported is the Symfony doctrine:schema:update but doctrine:schema:create --dump-sql works fine (if you remove the final ; on each line).
If you need doctrine:schema:update you can try to fix the methods for this in the platform. The method is located in Doctrine\DBAL\Platforms\ASEPlatform::getListTableColumnsSQL. Probably others need to be changed as well.
While working on the driver i always have oriented myself on the MS SQL driver implementation because Sybase ASE and MS SQL originally where the same product. Therefore, the syntax is still very similar.

I hope I could help you with my explanations. If you have any further questions don't be afraid to ask me in this PR or my mail. You find my E-Mail address on my profile.

Of course I would love to see your contributions to this implementation.

A good starting point to see the discussion about this driver here in the doctrine project is probably by having a look into my PR's:
https://github.com/doctrine/dbal/pulls/Deltachaos

If you have contributions please send me PR's to the following repositories:

@bakritarek
Copy link

Hello I am working with Sybase and i want use Symfony.

There is not an installation video that can help us with the tasks
Thanks

@Deltachaos
Copy link
Contributor Author

@klauUs if you want i can help you to get this running. Just contact me at mr@deltachaos.de

@Deltachaos
Copy link
Contributor Author

@klauUs @gnascimento I have moved the code to a separate package so that you can use it without using my (currently outdated) branch of doctrine/dbal.

Have published the package xtain/dbal-platform-ase. You then can configure it using a custom driver class and choose between Doctrine\DBAL\Driver\ASE\Driver and Doctrine\DBAL\Driver\PDOASE\Driver.

@morozov morozov closed this Nov 30, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants