Blog Archives

Doctrine ORM with Oracle’s OFFSET and LIMIT

To handle LIMIT and OFFSET within Oracle DBs you have to use some magic. There is a Blog post, which describes the general procedure. Doctrine uses this ROWNUM stuff too, it is implemented within OraclePlatform.php. Doctrine needs two integer values for LIMIT and OFFSET. But you can also set both to NULL, the methods of the Query class (setMaxResults() and setFirstResult()) accept NULL values too.

If you think, it is a good idea to send  PHP_INT_MAX as default for LIMIT, it would be a fail. Within the OraclePlatform.php Doctrine must add the given OFFSET (maybe 20) to the LIMIT (maybe PHP_INT_MAX), so you will run into a datatype overflow. This will result into PHP_INT_MIN, a very large negative number. The resulting SQL would try to filter your ResultSet from OFFSET (20) to a large negative number, it would be empty always (except you will set the OFFSET to 0).

Also, if you set a large LIMIT to force getting all records from a query, you force Doctrine to wrap your query with some of the ROWNUM stuff, which results in a more complex query and an increased query time. Let LIMIT = null, if you need all records. Only set OFFSET > 0 (or != null), if you need the next page of the results.

 

Access private Gitlab repo with Composer

To access a project (like a library) on a private repository within your own Gitlab server, it is necessary to configure Composer right. First add the repository to the composer.json file of the current project (where you need the library code):

{
"repositories": [{
"type": "gitlab",
"url": "https://gitlab.yourserver.com/user/project.git" }]

The type “gitlab” activates some more configuration properties for Composer. So you have to define your private Gitlab server as valid server within Composer:

composer config --global gitlab-domains "gitlab.yourserver.com"

The –global flag stores the property within ~/.config/composer/config.json (OpenSuse 15.2). It will be activate for every Composer project on the computer.

If your repository is only visible after the login with a user/password, you must generate a unique token within the GitLab. Log into the GitLab UI with your username/password and choose “Preferences”->”Access Tokens”. There you can enter an application name like “PHP composer” and select “read_api” permissions. You get a new token, which you now can use within Composer config.

It is necessary to define the username and the access token for your Gitlab account, to provide access to the repository:

composer config gitlab-token.username "your GitLab username"
composer config gitlab-token.gitlab.yourserver.com "generated token"

Here you could also add –global or leave it and define the token only for the current project. The lines above should generate a file auth.json within your current project:


{
"gitlab-token": {
"username": "your GitLab username",
"gitlab.yourserver.com": "generated token"
}
}

Now you need a prepared repository on “https://gitlab.yourserver.com/user/project.git” (the library project). On the top level of the master branch there must be a composer.json file, which should not contain a version number, but a valid “name” property like (and “require” and “autoload” sections):


{
"name": "company/private_library"
}

The possible versions of your library will be extracted from the tags or branches of the project. Some Information about versions you can find on the composer website. The simplest way is to generate a tag of your latest commit and name it like “v1.0.0”. Now it is possible to define the library repository as a requirement within your current project:


{
"require": {
"company/private_library": "1.0.*"
}
}

You can use the version handling of Composer, if your tags will have valid version numbers. It is also possible to use stability constraints like “stable” or “dev”, use it within your tag name like “v1.0.0-dev”


{
"require": {
"company/private_library": "1.0.*@dev"
}
}

A following composer update should clone the repository into your vendor directory and the autoloader can provide the library project classes.