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

Question: Setting Serialized Mode in PCL #35

Closed
sudmanche opened this issue May 30, 2014 · 10 comments
Closed

Question: Setting Serialized Mode in PCL #35

sudmanche opened this issue May 30, 2014 · 10 comments

Comments

@sudmanche
Copy link

Hi, in non PCL version of SQLite.Net I was able to do this for Android and iOS:

        SQLite.SQLite3.Shutdown();
        SQLite.SQLite3.Config(SQLite.SQLite3.ConfigOption.Serialized);
        SQLite.SQLite3.Initialize();

and this would stop the threading error.

I cannot see how to set serailize mode with the PCL. Can you explain please.

@sudmanche
Copy link
Author

searching through the code I have found that in SQLite.Net.Interop.ISQLiteApi the following line.

    //        Result Config(ConfigOption option);

so the ability to set the config is not implemented. Is there a reason why? With the non-PCL I had to set Serialized to avoid getting SIGSEVC errors on multi thread access.

@oysteinkrog
Copy link
Owner

I'm not sure why this is, it might simply be a mistake.
Does everything work if you uncomment it?

@sudmanche
Copy link
Author

unfortunately not!

it seems all of these are not implemented in the Internal, or defined in the interface.

    [DllImport("sqlite3", EntryPoint = "sqlite3_initialize", CallingConvention=CallingConvention.Cdecl)]
    public static extern Result Initialize();

    [DllImport("sqlite3", EntryPoint = "sqlite3_shutdown", CallingConvention=CallingConvention.Cdecl)]
    public static extern Result Shutdown();

    [DllImport("sqlite3", EntryPoint = "sqlite3_config", CallingConvention=CallingConvention.Cdecl)]
    public static extern Result Config (ConfigOption option);

I'll see what I can do to test the implementation of these, but I do not have an environment to build for all platforms unfortunately.

@sudmanche
Copy link
Author

I have attempted to make the necessary changes to add in this functionality. As mentioned I cannot do all platforms, and some I have no ability to test. I am testing for Xamarin iOS and Android.

the changes I have made to source are

  1. In SQLite.Net.Interop.ISQLiteApi
    add in extra items to the Interface.

    Result Initialize();
    Result Shutdown();
    Result Config(ConfigOption option);
    
  2. In each Platform - SQLiteApi[Platform]Internal.cs file
    add relevant dllimports (win32 uses Interop, WinRT has none) as below (config was defined, but no concrete implementations)

    [DllImport("sqlite3", EntryPoint = "sqlite3_initialize", CallingConvention = CallingConvention.Cdecl)]
    public static extern Result sqlite3_initialize();
    
    [DllImport("sqlite3", EntryPoint = "sqlite3_shutdown", CallingConvention = CallingConvention.Cdecl)]
    public static extern Result sqlite3_shutdown();
    
  3. In each SQLiteApi[Platform].cs file
    add concrete implementations

    public Result Initialize()
    {
        return SQLiteApiAndroidInternal.sqlite3_initialize();
    }
    public Result Shutdown()
    {
        return SQLiteApiAndroidInternal.sqlite3_shutdown();
    }
    
    public Result Config(ConfigOption option)
    {
        return SQLiteApiAndroidInternal.sqlite3_config(option);
    }
    

++++++++++++++++++

Ok, so I have only done some limited testing so far, but seems to solve my problem which was on Android. I have not touched WindowsPhone8 as I cannot load it into VisualStudio.

What would you like me to do with the files I have modified? I could (try) and create a fork on Git hub and commit them up? (note: I am not very familiar with Git, but am willing to try this), or zip them up and send them to you, or maybe you don't need/want them anyway.

@sudmanche
Copy link
Author

tried to contribute my changes by creating a pull request, but it did not work as I expected.
I really don't know what I have to do in Git & GitHub to contribute my changes.

@sudmanche
Copy link
Author

Have now forked and committed the files I have changed. let me know what to do next?

https://github.com/sudmanche/SQLite.Net-PCL

@oysteinkrog
Copy link
Owner

Hi, to create a pull request you should create a new branch on your repo and then you can use github to create a PR.

Regarding this change, I think it's a good idea to add it back, but I fear there are some platforms that do not support/implement the necessary sqlite3 functions.
I am not 100% sure how to handle it in those cases, I see at least two viable options:

  1. Add a new interface (e.g. ISQLiteApiEx) for the new functions, then consumers can check if the platform supports it by using the is/as keywords.
  2. Have the unsupported exceptions throw NotSupportedException

@has-taiar
Copy link

So has this been merged?

@oysteinkrog , throwing a NotSupportedException is the right thing in this case, as the operation IS really not supported on that platform.
I have just spent an hour migrating from SQLite.NET to this library and I am very happy with the results, but I need to have the ability to change the config as this causes issues with multi-threading apps.
Any idea when would this be merged?

Thanks a lot for the great effort everybody :)

@oysteinkrog
Copy link
Owner

Hi @has-taiar, nothing has been merged yet.
I think I agree that a NotSupportedException is the best solution, I would be happy to merge a PR that included that.

@sudmanche
Copy link
Author

I have attempted to do all neccessary changes, and created a pull-request #39.
hope this helps and is correct.

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

3 participants