yajra / pdo-via-oci8

PHP PDO_OCI functions via OCI8 extension
Other
88 stars 61 forks source link

Fixing issues with get "checkSequence()" and "lastInsertId()" #18

Closed mohsenie closed 9 years ago

mohsenie commented 9 years ago

Fixing issues with get "checkSequence()" and "lastInsertId()". I encountered problems getting last insert ID and it seems that the issue is with a wrong statement.

yajra commented 9 years ago

Can you please paste an example code on how to reproduce the error?

mohsenie commented 9 years ago

Hi Yajra,

Thanks for your comment. I am not sure what version of Oracle Sql your are using to test this by on my the correct format is :

SELECT COUNT(*) FROM all_sequences WHERE SEQUENCE_NAME=UPPER('BOOKS_SEQ');

This will return count of sequences for BOOKS_SEQ.

However with the original code I get something like :

select count(*) from all_sequences where sequence_name=upper('books_BOOKS_seq') and sequence_owner=upper(user)

This i will simply fail to run on Oracle because the sequence name is wrong.

Regards, Mohsen

yajra commented 9 years ago

Hi Mohsen,

Are you using this package as stand alone or with Laravel? I am using this package for Laravel and it uses the convention I mentioned when creating a sequence via migration. If you are using this as stand alone, then I guess I should make some improvements to make your case work. For Laravel part, this is working well.

Regards!

mohsenie commented 9 years ago

Hi Yajra,

Thank you for your reply.Firstly let me thank you guys for releasing this to the community because it helped me a lot. Since the PDO driver for OCI is deprecated this came in very handy to get codeception work with Oracle without major changes.I think it makes a lot sense to make it a general PDO proxy driver for oci8 and not specific to Laravel.

Regards, Mohsen

yajra commented 9 years ago

Hi Mohsen,

I have an idea on how to make this work for your case. However, just to make sure, can you please provide some example codes on how you are using this package? I will verify my solution based on your example. Thanks!

yajra commented 9 years ago

Hi Mohsen, this should be fixed on v0.11.0. Try checking it out. However, please note that you should pass the full sequence name in lastInsertId for it to work. See example below:

$pdo->lastInsertId(); // will use TABLE_ID_SEQ
$pdo->lastInsertId('TABLE_SEQ'); // will use TABLE_SEQ
alfmel commented 9 years ago

Mohsen,

About a year ago I forked Arjay's code to make it more generic. I've switched jobs and no longer have to use Oracle, so I haven't done much with it. But you can check it out. Feel free to fork and continue develoment.

https://github.com/alfmel/pdo-via-oci8

mohsenie commented 9 years ago

Below is a sample class where I am actually using this :

https://gist.github.com/mohsenie/745a56e9f4709f3832fd#file-gistfile1-php

yajra commented 9 years ago

I see. I think your issue would be fixed by v0.11.0 and updating your lastInsertId function to.

    public function lastInsertId($table)
    {
        return $this->getDbh()->lastInsertId($table.'_SEQ');
    }