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

CraueGeoBundle & sqlite3: SQLSTATE[HY000]: General error: 1 no such function: ASIN #12

Open
azine opened this issue Apr 21, 2016 · 7 comments

Comments

@azine
Copy link

azine commented Apr 21, 2016

Hi,

thank you very much for the cool bundle. Works like a charm with my MySQL backend.

...unfortunately it does not with my installation of sqlite3 (on Ubuntu 15.04) that I use to run unit-tests on.

I always get the following error "SQLSTATE[HY000]: General error: 1 no such function: ASIN".

Googling around I found out the cause could be, that I need to install an extension for sqlite (=> http://www.sqlite.org/contrib/download/extension-functions.c?get=25).

As I didn't manage to install it on my Ubuntu machine, I wanted to ask two things:

  1. am I on the right track an must install that extension or is it something else?
  2. do you know of a place/url with (working) instructions to get the extension installed?

Thanx a lot for your help.
Dominik

@craue
Copy link
Owner

craue commented Apr 22, 2016

I'm afraid I cannot help you with this. SQLite is currently not supported and I guess that won't change due to these missing math functions.

@azine
Copy link
Author

azine commented Apr 22, 2016

Hi Christian,

thanx for the feedback. I was afraid that would be your answer. :-/

If I manage to work around the problem (e.g. install the extensions), I'll
post a short "how-to" here.

Cheers,
Dominik

2016-04-22 5:40 GMT+02:00 Christian Raue notifications@github.com:

I'm afraid I cannot help you with this. SQLite is currently not supported
and I guess that won't change due to these missing math functions.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#12 (comment)

@robertfausk
Copy link

@azine I think you're on the right way.
Maybe this will help you: https://www.sqlite.org/loadext.html

@robertfausk
Copy link

@azine I investigated little bit further. It seems that you first have to install the extension and then load the extension via load_extension()
Additionally you have to allow/enable extension loading for sqlite.

Following library uses extension loading:
https://github.com/brick/geo#using-sqlite3-with-spatialite
I think for our use case we simply have to use the math extension instead of spatialite extension.

@azine
Copy link
Author

azine commented May 3, 2016

Hi @robertfausk,

I already managed to get the math functions from "extension-functions.c" loaded into sqlite.

Instructions are inside the extension-functions.c file... I used gcc -fPIC -shared extension-functions.c -o libsqlitefunctions.so -lm to compile the code (note the -lm is at the end of the line).

I can now call the new math functions by executing a "native query" through Doctrine.

But there is still one step missing, because Doctrine does not yet know that sqlite is able to handle those math functions. The functions are not part of the doctrine-sqlite-mapping.

So I'll have to look into "teaching" Doctrine that sqlite is now able to calculate asin and acos etc.

When I managed to get all the pieces to work, I'll post some instructions here.

Cheers,

@azine
Copy link
Author

azine commented May 10, 2016

Hi,

I managed to get the asin/acos functions working in sqlite and also in doctrine by compiling the extension as described above, placing it in bin/sqlite-extension/libsqlitefunctions.so and adding the following code to the app/AppKernel.php.

    protected function initializeContainer() {

        parent::initializeContainer();

        if ('test' !== $this->getEnvironment()) {
            return;
        }

        // load the math function for sqlite
        $manager = $this->getContainer()->get('doctrine.orm.entity_manager');
        if($manager->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform){
            $extensionFile = realpath(__DIR__."/../bin/sqlite-extension/libsqlitefunctions.so");
            $statement = $manager->getConnection()->prepare("SELECT load_extension('$extensionFile');");
            if(!$statement->execute()){
                throw new \Exception("unable to load libsqlitefunctions.so from $extensionFile");
            }
            $statement = $manager->getConnection()->prepare("SELECT ASIN(1) as a;");
            $statement->execute();
            $result = $statement->fetchAll();
            if($result[0]['a'] !== "1.5707963267949"){
                throw new \Exception("unable to execute the asin function, loading libsqlitefunctions.so from $extensionFile probably failed.");
            }
        }
    }

It's probably not the nicest way, but for now it works.

Cheers,

@Headd2k
Copy link

Headd2k commented Aug 13, 2021

For Windows users: My PHP on my Windows machine also complained about the missing "ASIN" function when using SQLite.

I was able to fix this by replacing the "libsqlite3.dll" file found in my PHP directory with the sqlite3.dll (rename to libsqlite3.dll) found in the .zip file on the official SQLite download page (https://www.sqlite.org/download.html) under the section "Precompiled Binaries for Windows".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants