Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

WebGL + Sqlite Unable to load DLL 'sqlite3'

Discussion in 'WebGL' started by Zape, Nov 29, 2021.

  1. Zape

    Zape

    Joined:
    Jun 12, 2013
    Posts:
    31
    Hi.

    I can deploy my game in WebGL but I'm not able to use sqlite.
    Does anybody know if is possible to use sqlite in WebGL or any workaround?

    Thanks!
     
    Yasu1118 likes this.
  2. MarcelPursche

    MarcelPursche

    Unity Technologies

    Joined:
    Mar 3, 2021
    Posts:
    44
    Hi,
    the WebGL platform does not support dynamic linking. But it should be possible to statically link the sqlite3 library.
    For what purpose are you using the sqlite database? The WebGL platform has a virtual file system build on top of Indexed DB API. If your database is pretty large or you are doing a lot of write operations the performance might not be that good on the WebGL platform. Depending on the use case it might make sense to use the Indexed DB API directly or use a database that is running on a server and is accessible through a Web API.
     
  3. jacksonkr

    jacksonkr

    Joined:
    Jan 22, 2013
    Posts:
    22
    I'm not sure about @Zape but for my purposes sqllite is the format I receive the data in and the async sqlite abilities seem impacted by webgl:

    The runtime is officially stopping after the line
    var raw = await dbconn.ExecuteScalarAsync<byte[]>(sql);


    and the type of
    dbconn
    is
    SQLiteAsyncConnection
    which I believe is third party code, but I can't easily put a finger on where ours came from.

    The full method:
    Code (CSharp):
    1.  
    2. public async UniTask<MBTileData> GetMBTileDataByKey(TileKey tileKey)
    3.     {
    4.         try {
    5.             SQLiteAsyncConnection dbconn = this.OpenConnection(this._enumId);
    6.  
    7.             MBTileData tileData = null;
    8.  
    9.             var sql = $@"
    10.                SELECT tile_data FROM tiles
    11.                WHERE tile_column = {
    12.                            tileKey.x}
    13.                AND tile_row = {
    14.                            tileKey.y}
    15.                AND zoom_level = {tileKey.z}
    16.                ";
    17.  
    18.             var raw = await dbconn.ExecuteScalarAsync<byte[]>(sql);
    19.             if(raw == null || raw.Length <= 0) return null;
    20.  
    21.             using (var outputStream = new MemoryStream(raw))
    22.             {
    23.                 using (var zipStream = new GZipStream(outputStream, CompressionMode.Decompress))
    24.                 {
    25.                     await UniTask.RunOnThreadPool(() => {
    26.                         tileData = Serializer.Deserialize<MBTileData>(zipStream);
    27.                     });
    28.  
    29.                     // await zipStream.ReadAsync(raw, 0, raw.Length); //depending on the encoding the count may not be result.Length
    30.                     // Debug.Log(zipStream.BaseStream.Length);
    31.                     // await zipStream.FlushAsync();
    32.                 }
    33.             }
    34.  
    35.             return tileData;
    36.             // mbTile.ReceiveMBTileData(tileData);
    37.         } catch(Exception err) {
    38.             Debug.LogWarning(err);
    39.         }
    40.  
    41.         return null;
    42.     }
    43.  
     
  4. Oksana-Iashchuk

    Oksana-Iashchuk

    Joined:
    Sep 10, 2012
    Posts:
    126
    You can work with sqlite in WebGL but only if you use sqlitekit asset.