Editor: Sybase database support
Editor: Sybase database support
Lolo
Posts: 42Questions: 7Answers: 1
Hello,
I would like to know if there is any plan to support Sybase / Sql Anywhere database driver like you already do with Sql Server, Oracle, ...
Or do we have to create an unofficial Odbc driver support in order to use Editor componant?
The problem with Odbc driver is that last_insert_id is not supported.
Thanks in advance and have a nice day.
This discussion has been closed.
Replies
Hi,
Currently there is no plan to directly support Sybase / Sql Anywhere - to be honest this is the first request for such support. It appears that there is a PDO driver available for SQL Anywhere, which means that it should be possible to support Sybase with a suitable Editor driver.
Allan
Thanks for your answer and I will have a look to this.
But for the moment, I have created a new driver entry named Sybase which is a clone of Mysql driver folder.
I named it DriverSybaseQuery and I have simply changed the connection string for using odbc driver (with a DSN) as I have Sybase installed on my computer.
It works well to get and update data into database but when I try to insert a new data into the database I have the following error message:
SQLSTATE[IM001]: Driver does not support this function: driver does not support lastInsertId()
So what is the best way to make it works?
I suppose I have to call the following sql command: @identity AS LastID;
But the question is where and how I am supposed to do this.
In Result.php file into public function insertId ()
Any help would be greatly appreciated.
Thanks in advance and have a nice day.
If you have a look in the Oracle Query.php and Result.php files you'll be able to see one possible approach for how to handle such a situation. In that driver I've used
RETURNING
from an insert command to get the primary key value and stick it into a private variable, ready for the result to return if needed.That assumes of course that you can get the id using RETURNING. If you can't you'd need to execute another SQL statement in the Result's id method.
Allan
Hi allan and thank you for your answer.
Sybase does not have this feature and you have to use @identity in order to get the last inserted id into a table.
For users who could be interested, here is what I have done.
In the Result.php file, I have modified the insertId function like below:
public function insertId ()
{
$lastInsertId = 0;
try {
$identity = $this->_dbh->@identity AS LastId');
$identity->execute();
$row = $identity->fetch(\PDO::FETCH_ASSOC);
$lastInsertId = $row['LastId'];
}
catch (PDOException $e) {
echo "An SQL error occurred: ".$e->getMessage();
error_log( "An SQL error occurred: ".$e->getMessage() );
return false;
}
return $lastInsertId;
//return $this->_dbh->lastInsertId();
}
I am not sure if it is the best method but it works well.
Allan, do you want me to send you files I have created and modified in order to see how I have add Sybase support for Editor component?
It could be nice to have Sybase support for other users.
Very nice - thanks for your code. If you could send me that files that would be great - although I see what you've done from the above. allan @ this domain.net will come to me.
I'm currently looking into better options for expanded automated testing of the various database options supported by Editor. When that is in place I'll look at adding proper Sybase support in Editor.
Allan