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

IllegalArgumentException: File contains a path separator - Cannot create sqldelight file on ios application group directory #1787

Closed
mikezliu opened this issue Jun 15, 2020 · 6 comments
Labels

Comments

@mikezliu
Copy link

mikezliu commented Jun 15, 2020

I'm trying to create the sqlite file on iOS in the application group directory so it can be shared between the main app and the today notification center widget. I've created sqlite files and shared it successfully this way in the past, just not using sqldelight.

let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.identifier")!
let file = url.path + "/" + Schema.FILE_NAME

val dbConfig = DatabaseConfiguration(
                name = file,
                version = Schema.version,
                foreignKeyConstraints = true,
                create = { connection ->
                    wrapConnection(connection) { Schema.create(it) }
                },
                upgrade = { connection, oldVersion, newVersion ->
                    wrapConnection(connection) { Schema.migrate(it, oldVersion, newVersion) }
                }
        )

        return NativeSqliteDriver(
                dbConfig)

Runtime Environment
SQLDelight version: 1.3.0
Application OS: iOS

Describe the bug

Exception:

Uncaught Kotlin exception: kotlin.IllegalArgumentException: File
/Users/username/Library/Developer/CoreSimulator/Devices/63D82DB4-4A53-4931-906C-BB63480D651C/data/Containers/Shared/AppGroup/23F1DE03-88A2-4840-BB83-037915A442B9/db contains a path separator

It seems in DatabaseConfiguration there is a hard requirement that the sqlite file doesn't contain path separators:

if (name.contains("/")) {
        throw IllegalArgumentException(
            "File $name contains a path separator"
        )
    }

Putting the sqlite file in the application group directory is a pretty common scenario to share data with extensions - is there any way to do this? Can this path check be removed? Thanks

@mikezliu mikezliu added the bug label Jun 15, 2020
@mikezliu
Copy link
Author

Oh I noticed a path property for the config, will give that a try!

@ghost
Copy link

ghost commented Feb 16, 2022

@mikezliu I don't see it. How did you do it?

@mikezliu
Copy link
Author

val dbConfig = DatabaseConfiguration(
                name = Schema.FILE_NAME,
                version = Schema.version,
                extendedConfig = DatabaseConfiguration.Extended(
                        foreignKeyConstraints = true,
                        basePath = path
                ),

@mikezliu
Copy link
Author

Path should be

let path = PKPersistentContainer.defaultDirectoryURL()

@ghost
Copy link

ghost commented Feb 16, 2022

Thank you!

@silverhammermba
Copy link

For my app I had to use

[[[[NSFileManager alloc] init] containerURLForSecurityApplicationGroupIdentifier:@"myIdentifier"] absoluteString]

for basePath. I injected this into my Kotlin code in the same way that I injected the Context for my Android driver.

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

No branches or pull requests

2 participants