Giter Club home page Giter Club logo

grdb.swift's People

Contributors

alextrob avatar baekteun avatar barnettben avatar charlesmchen-signal avatar chrisballinger avatar eburns-vmware avatar fpillet avatar gettoset avatar gjeck avatar groue avatar guidedways avatar gusrota avatar hartbit avatar kdubb avatar kustra avatar mallman avatar martinp7r avatar marus avatar mattgallagher avatar michaelkirk avatar mtancock avatar naveensrinivasan avatar pakko972 avatar peter-ss avatar sberrevoets avatar sobri909 avatar steipete avatar swiftlyfalling avatar timaellis avatar wuyuehyang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grdb.swift's Issues

Consider opening up Database for initialisation

Until GRDB is fully re-entrant it's hard to use in an application that may require nested transactions. For those of us willing to externally enforce Swift/sqlite3's threading rules it would be valuable to just have a raw database...

In my particular case I need a function to start a transaction, run a callback ( passing the database to that callback )

sqlite3.h path is hardcoded

The compiler could not find sqlite3.h because its hardcoded path in DRDB.swift.modulemap was incorrect on my machine

Consider using fatalError instead of precondition

Because GRDB is a dependency, when installed via Carthage it's compiled under release mode which means the precondition messages are lost.

I've found it sort of painful to do a debugging dance with GRDB ( have to re-compile with --configuration Debug in carthage ) just to get the precondition error messages to figure out what programmer error I've made.

If you instead had a custom "check" method that fired a fatalError instead of a precondition it would:

  1. Ensure that undefined and programmer error behaviour can never be released (-Ounchecked would skip these)
  2. Ensure via Carthage these errors are printed to the console.

Curious what other libraries are doing to. In SnapKit we're ensuring we use fatalError's.

[XCode7.3 beta] Could not build Objective-C module 'GRDB'

Cannot compile with Xcode 7.3 beta , 7.2.1 works just fines.

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/module.modulemap:1:8: error: redefinition of module 'Compression'
module Compression [system] [extern_c] {
^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/include/module.modulemap:1:8: note: previously defined here
module Compression [system] [extern_c] {
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/module.modulemap:6:8: error: redefinition of module 'Darwin'
module Darwin [system] [extern_c] {
^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/include/module.modulemap:6:8: note: previously defined here
module Darwin [system] [extern_c] {
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/module.modulemap:1599:8: error: redefinition of module 'os'
module os [system] [extern_c] {
^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/include/module.modulemap:1599:8: note: previously defined here
module os [system] [extern_c] {
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/module.modulemap:1615:8: error: redefinition of module 'libkern'
module libkern [system] [extern_c] {
^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/include/module.modulemap:1615:8: note: previously defined here
module libkern [system] [extern_c] {
^
:0: error: could not build Objective-C module 'GRDB'

/Pods/GRDB.swift/GRDB/Core/Support/CoreGraphics/CGFloat.swift

Null field causes error on fetch

If I have a Record something like this,
class Thing: Record {
var id: Int64!
var name: String
var description: String?
If I have a NULL value in the database for description, Thing.fetch causes 'fatal error: Could not convert NULL to String'. Shouldn't declaring description as String? allow for NULLs? What am I doing wrong?

Trouble building GRDB with Carthage

Hi,

I'm having trouble compiling GRDB.swift.

I'm using carthage and never had trouble until recent releases when I've been getting this:

The following build commands failed:
CompileC /Users/raymond/Library/Developer/Xcode/DerivedData/GRDB-gdcllwrgfoeepnekbbfhunfrgxgp/Build/Intermediates/sqlcipher.build/Release-iphoneos/sqlcipher.build/Objects-normal/arm64/sqlite3.o sqlite3.c normal arm64 c com.apple.compilers.llvm.clang.1_0.compiler
CompileC /Users/raymond/Library/Developer/Xcode/DerivedData/GRDB-gdcllwrgfoeepnekbbfhunfrgxgp/Build/Intermediates/sqlcipher.build/Release-iphoneos/sqlcipher.build/Objects-normal/armv7/sqlite3.o sqlite3.c normal armv7 c com.apple.compilers.llvm.clang.1_0.compiler
CompileC /Users/raymond/Library/Developer/Xcode/DerivedData/GRDB-gdcllwrgfoeepnekbbfhunfrgxgp/Build/Intermediates/sqlcipher.build/Release-iphoneos/sqlcipher.build/Objects-normal/armv7s/sqlite3.o sqlite3.c normal armv7s c com.apple.compilers.llvm.clang.1_0.compiler
(3 failures)
configure: error: in `/Users/raymond/Documents/Xcode/KSClaim/Carthage/Checkouts/GRDB.swift/SQLCipher/src':
configure: error: C compiler cannot create executables
clang: error: no such file or directory: '/Users/raymond/Documents/Xcode/KSClaim/Carthage/Checkouts/GRDB.swift/SQLCipher/src/sqlite3.c'
clang: error: no input files
clang: error: no such file or directory: '/Users/raymond/Documents/Xcode/KSClaim/Carthage/Checkouts/GRDB.swift/SQLCipher/src/sqlite3.c'
clang: error: no input files
clang: error: no such file or directory: '/Users/raymond/Documents/Xcode/KSClaim/Carthage/Checkouts/GRDB.swift/SQLCipher/src/sqlite3.c'
clang: error: no input files
A shell task failed with exit code 65:
** BUILD FAILED **

Using array in SQL arguments

I'd like to use in sql expressions with array:

// SELECT * FROM table WHERE id IN (1,2,3,5,8)
db.execute("SELECT * FROM table WHERE id IN (?)", arguments: [[1,2,3,5,8]] )

but I get an error:
Contextual type 'DatabaseValueConvertible' cannot be used with array literal
What do you think about this?

Suggestions for ignoring change notification depending on source?

Thank you for a wonderful library. ๐Ÿ‘

My question regarding change notifications is perhaps most easily illustrated by an example.

Example:
An app syncs a local database to iCloud using CloudKit.
The syncing engine registers a TransactionObserver to monitor local database changes, and records them for uploading to CloudKit.
When changes in CloudKit (i.e. from another device) need to be synced back to the local device, what's the best method to ignore them in the syncing engine's TransactionObserver?

i.e. The syncing engine only needs to record (and sync) local database changes made by other parts of the app. So it would want to be able to ignore change notifications caused by its own database transactions.

Is there any suggested way to accomplish this currently? Perhaps some way to tag database write transactions with an app-defined tag/source (that could then be retrieved in the TransactionObserver events)?

Correct mechanism to load aggregates?

Simple aggregate case, I have an array of items.

CREATE TABLE container (id INTEGER PRIMARY KEY)
CREATE TABLE item (container_id INTEGER, name TEXT, val INTEGER)

So I have two structs to model this:

struct Item
{
   var value : Int64
   var name : String
}

struct Container
{
    var id : Int64
    var items : [Item]
}

I can apply RowConvertible to each of these, and I can then query them from the DB. But I am not sure of the correct way to construct the aggregate. The Container type really needs all the rows of the items in order to truly construct itself. But its row basically is just the id. Plus, I'm not sure from reading the docs if GRDB supports running another query (say, to get the items for a specific row) while an existing query is running (say, to get the containers in the db). I also can't really do this from RowConvertible interface as there is no mechanism to run a new query.

What is the recommended way to handle this situation?

Generic parameter T could not be inferred (Swift 2.2)

I am using the latest version from master branch on the latest Xcode and database queue creation does work. Now I am stuck with my first execution call which somehow does not want to compile.

I saw that there was an issue with Swift 2.2 some weeks ago and it was fixed so I donโ€™t know why that error occurs :(

screenshot 2016-05-11 at 15 26 45

setting journal_mode throws and error

I'm trying to execute the following statements:

        try! db.execute("PRAGMA journal_mode=WAL")
        try! db.execute("PRAGMA synchronous=OFF")

if I comment out the first one then the second one works fine. But the first one gives the following error:

fatal error: 'try!' expression unexpectedly raised an error: SQLite error 100 with statement PRAGMA journal_mode=WAL;: unknown error: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.1.101.15/src/swift/stdlib/public/core/ErrorType.swift, line 50

if I copy and page the journal mode command and run it on the command line it runs fine and properly sets the journal mode.

Any idea what's going on here?

UpdateStatement.Changes struct members not public

I'm getting these errors:

'UpdateStatement.Changes' does not have a member named 'changedRowCount'
'UpdateStatement.Changes' does not have a member named 'insertedRowID'

I was able to fix it by adding a public keyword to both variables

Initializers should be failable and functions should throw errors

First example:
init(_ row: Row)

The problem is that the object convertible (Record for example) may not be directly convertible from a row. The data might have changed or the rules for the data model have changed.

I think this should be:
init(_ row: Row) throws
OR:
init?(_ row: Row)

Second example: Database fetches using fetch, fetchAll, and fetchOne are currently assuming statements will succeed and use try!. I think these functions should declare that they may throw an error.

override Record.description

This maybe an issues with my knowledge of Swift

class Group: Record  {
    var name: String
    var description: String
    var enabled: Bool

I get an error cannot override member variable (description) ...
Is there a way around this short of using a different name?

Enhancement: Allow removing rows based on primary key

If I have a table that has a single-column primary key, simply implementing TableMapping and RowConvertible allows me to fetch items according to primary key. Nice.

What about removing items? At the moment, I am finding myself adding code many places that implements removal with an SQL statement, but GRDB should know all the info it needs to remove using the primary key. I don't want to have to implement Persistable for this, in fact, I don't want to have to load an object at all. I should be able to do:

struct SomeRecordType : RowConvertible, TableMapping
{ ... }

SomeRecordType.removeOne(db, key: id)

Can this be made to work? I should only actually need TableMapping, not RowConvertible (but of course, no sense in doing one without the other).

Support for multi-column primary keys?

I have a table where the primary key is a tuple of the primary key of an owner table, and instance of the sub-item.

Docs say GRDB only supports fetching of single-column primary keys unless you use Record. Why not with just table mapping? e.g.:

// CREATE TABLE my_table (id INTEGER, instance INTEGER, PRIMARY KEY (id, instance))
struct MyRecord : Persistable, TableMapping
{
   var id : Int64
   var instance: Int
   init(_ row: Row)
   {
      id = row.value(named: "id")
      instance = row.value(named: "instance")
   }
   static func databaseTableName() -> String
   {
      return "my_table"
   }

   // why can't this be auto-added via extension?
   static func fetchOne(db: DatabaseReader, key: (Int64, Int)) -> MyRecord?
   { ... }
}

Build Error after 7.3 XCode Upgrade

I'm attempting to build 0.52.0 using Carthage and I'm getting the following error:

/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Pe*** Building scheme "SQLiteCipher Mac" in SQLite.xcodeproj
** BUILD FAILED **


The following build commands failed:
    CompileC /Users/chris/Library/Developer/Xcode/DerivedData/SQLite-atzbratnaofmvegdqilzwypbobbm/Build/Intermediates/sqlcipher.build/Release/sqlcipher.build/Objects-normal/x86_64/sqlite3.o sqlite3.c normal x86_64 c com.apple.compilers.llvm.clang.1_0.compiler
    CompileC /Users/chris/Library/Developer/Xcode/DerivedData/SQLite-atzbratnaofmvegdqilzwypbobbm/Build/Intermediates/sqlcipher.build/Release/sqlcipher.build/Objects-normal/i386/sqlite3.o sqlite3.c normal i386 c com.apple.compilers.llvm.clang.1_0.compiler
(2 failures)
rformance/SQLite.swift/SQLite/Extensions/FTS4.swift:31:49: warning: 'var' parameters are deprecated and will be removed in Swift 3
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Core/Value.swift:36:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Core/Value.swift:38:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Typed/Expression.swift:27:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Helpers.swift:33:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Helpers.swift:91:111: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Helpers.swift:95:78: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Helpers.swift:99:81: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Extensions/FTS4.swift:31:49: warning: 'var' parameters are deprecated and will be removed in Swift 3
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Core/Value.swift:36:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Core/Value.swift:38:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Typed/Expression.swift:27:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Helpers.swift:33:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Helpers.swift:91:111: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Helpers.swift:95:78: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Helpers.swift:99:81: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Extensions/FTS4.swift:31:49: warning: 'var' parameters are deprecated and will be removed in Swift 3
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Core/Value.swift:36:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Core/Value.swift:38:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Typed/Query.swift:917:60: warning: '++' is deprecated: it will be removed in Swift 3
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Typed/Query.swift:917:60: warning: '++' is deprecated: it will be removed in Swift 3
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Typed/Query.swift:923:13: warning: 'anyGenerator' is deprecated: renamed to 'AnyGenerator'
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Typed/Query.swift:894:68: warning: '++' is deprecated: it will be removed in Swift 3
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Typed/Query.swift:894:68: warning: '++' is deprecated: it will be removed in Swift 3
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Typed/Expression.swift:27:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Helpers.swift:33:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Helpers.swift:91:111: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Helpers.swift:95:78: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Helpers.swift:99:81: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Extensions/FTS4.swift:31:49: warning: 'var' parameters are deprecated and will be removed in Swift 3
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Core/Value.swift:36:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Core/Value.swift:38:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Core/Statement.swift:274:16: warning: 'anyGenerator' is deprecated: renamed to 'AnyGenerator'
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Core/Statement.swift:275:73: warning: '++' is deprecated: it will be removed in Swift 3
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Typed/Expression.swift:27:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Helpers.swift:33:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Helpers.swift:91:111: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Helpers.swift:95:78: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Helpers.swift:99:81: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Extensions/FTS4.swift:31:49: warning: 'var' parameters are deprecated and will be removed in Swift 3
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Core/Value.swift:36:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/Tests/Performance/SQLite.swift/SQLite/Core/Value.swift:38:5: warning: use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead
clang: error: no such file or directory: '/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/GRDB Tests/Performance/SQLite.swift/Vendor/sqlcipher/sqlite3.c'
clang: error: no input files
clang: error: no such file or directory: '/Volumes/Disk2/chris/Dropbox/elocinSoft/Projects/frequency/Carthage/Checkouts/GRDB.swift/GRDB Tests/Performance/SQLite.swift/Vendor/sqlcipher/sqlite3.c'
clang: error: no input files
A shell task failed with exit code 65:
** BUILD FAILED **


The following build commands failed:
    CompileC /Users/chris/Library/Developer/Xcode/DerivedData/SQLite-atzbratnaofmvegdqilzwypbobbm/Build/Intermediates/sqlcipher.build/Release/sqlcipher.build/Objects-normal/x86_64/sqlite3.o sqlite3.c normal x86_64 c com.apple.compilers.llvm.clang.1_0.compiler
    CompileC /Users/chris/Library/Developer/Xcode/DerivedData/SQLite-atzbratnaofmvegdqilzwypbobbm/Build/Intermediates/sqlcipher.build/Release/sqlcipher.build/Objects-normal/i386/sqlite3.o sqlite3.c normal i386 c com.apple.compilers.llvm.clang.1_0.compiler
(2 failures)

There are no issues when building in Xcode.

upgrade my preloaded database for app update

How can i upgrade my database (pragma user_version 1 to 2 ) with certain changes (like add new table or column) in my database and without changing any user changes made( eg : counter :- number of times an app was used) for my pre built database when updating an app (1.0 to 2.0).

Row.fetchAll failing

We are seeing an error with Row.fetchAll. This is happening in two different Macbooks. We are running the app on a simulator.

fatal error: 'try!' expression unexpectedly raised an error: SQLite error 14 with statement select * from user_profile: unable to open database file: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-703.0.18.1/src/swift/stdlib/public/core/ErrorType.swift, line 54

public class func getUserClientId() -> Int? {
    let db = try! DatabasePool(path: getDatabaseFile())

    for row in Row.fetchAll(db, "select * from user_profile") {
        let clientId : Int = row.value(named: "client_id")

        return clientId
    }

    return nil
}
(NSString*) getDatabaseFile {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(
                                        NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docsDir = [paths objectAtIndex:0];
    NSString *dbFile = [docsDir
                        stringByAppendingPathComponent: @"database.dat"];
    NSLog(@"Database file: %@", dbFile);

    return dbFile;
}

Crashing fetchOne call

I am getting deeper and deeper into GRDB. To avoid crashes, I am wrapping all my try db.inDatabase{...} calls in a do..catch block and can perfectly catch errors.

But for a fetchOne call (SELECT) using try is not possible because fetchOne seems to internally do a try!. Now, if I am using invalid SQL in a fetchOne then my app is crashing :(

Are there alternatives to the fetch command which return rows from SELECT and which are properly crash-marked?

Maybe you can replace every try! with try?

Here is an excerpt of an example which creates a crash:

....
// LIMIT 1 must come after ORDER -> the SQL is invalid which leads to a crash
let sql = "SELECT * FROM \(table) WHERE \(column)=:val LIMIT 1 ORDER BY id DESC"
db.inDatabase { db in
    if let row = Row.fetchOne(db, sql, arguments: ["val": value]) {
        ret = row
    }
}
return ret
...

Crash during deinit of DatabaseQueue

This commit introduces deinit for DatabaseQueue.
005c4de

Which gives me the following crash on deinit:

*** NSForwarding: warning: object 0x7f96e526a550 of class 'GRDB.DatabaseQueue' does not implement methodSignatureForSelector: -- trouble ahead
Unrecognized selector -[GRDB.DatabaseQueue FXNotifications_observers:]

Perhaps DatabaseQueue should also inherit from NSObject?

Need to add RowConvertible to non-GRDB aware class.

I have a situation where I would like to separate out the mechanism used to load class instances using GRDB from the base type itself.

RowConvertible requires init(_ row: Row) function, but for non-final classes, this cannot be an extension, which means that I can't "tack on" compatibility with GRDB with an extension to something that has no knowledge of GRDB.

I think it would be good to be able to use a factory method which swift does not place extra requirements on, so you can apply GRDB compatibility completely using extensions.

Something like:

protocol FactoryRowConvertible {
   static func loadFromRow(row: Row) -> Self
}

Apologize if I got this wrong syntax-wise, I'm somewhat new to Swift.

Then all the extensions added to RowConvertible could do the same with FactoryRowConvertible.

Failed to run the first code

Hi,

It's unfortunate for me not to be able to install this great lib. I followed your instruction - Manual. After the 4 steps (download, drag&drop GRDB.xcodeproj to my project, add GRDBiOS to Target Dependencies in Build Phases of my app, add GRDB.framework to Embedded Binaries in General tab of my app), I get this error in my ViewController.swift:

screen shot 2016-05-10 at 7 03 57 pm

2 questions:

  1. As in the warning, do I have to import the GRDB?
  2. Why after the 4 steps, I still cannot compile my first line of code with DatabaseQueue?

Please show me how to solve my issues.

Note that I am using XCode 7.3.1.

Thanks a lot

No error when opening a jpg as a database

I attempt to open a jpg file as a database and do not get any error. This must be wrong?
url is pointing to a .jpg file

`var config: Configuration = Configuration()

    config.trace = { print($0) }
    config.readonly = true

    let dbQueue = try! DatabaseQueue(path: url.path!, configuration: config)`

0.52.0 Swift Errors

Hello,

thx for this great tool ๐Ÿ‘

But I found some compiling errors...

bildschirmfoto 2016-03-22 um 00 21 32

bildschirmfoto 2016-03-22 um 00 20 19

Generic Parameter 'T'could not be inferred

dbQueue.inDatabase { db in let expandedText = String.fetchOne(db, "SELECT expandedText FROM words") return expandedText }

Am I missing something here?
What is wrong with this?

Full-text Search

It is a must-have requirement for my app and as far as I understand SQLite it is somehow already built-in. I know how to use it in SQLite.swift and already implemented it there (documentation) but I would prefer GRDB over SQLite.swift because it is more light-weight and also seems to be more actively maintained.

I want to index a longer message string for log entries with full-text search. For that to accomplish I need to be able to create a VirtualTable which stores the reference ID of the entries table and the message text with .FTS4

In SQLite.swift I did the following line:

try db.run(table.create(.FTS4([cols.entriesID, cols.message], tokenize: .Porter)))

What do I need to do to make it work with GRDB?

dyld: Library not loaded

I use my iPhone 6 test the program:

dyld: Library not loaded: @rpath/GRDB.framework/GRDB
Referenced from: /var/mobile/Containers/Bundle/Application/3E9FBA0D-0CCD-4F02-B29B-946AAE91CF4A/TSPTest.app/TSPTest
Reason: image not found

Enhancement: Allow initializing rows using a mapping

RowConvertible takes a Row object, and allows one to initialize an object based on the fields in the row.

However, you may fetch more than one object per row with a join. If you wanted to intialize two objects, you may rename some of the fields to avoid collisions. But the initializer is expecting certain names in the row to match what it is looking for.

A basic example is let's say you have 2 types of items. Item1 has at most one Item2. Each of these match objects that can initialize from a row. However, each one expects the field "id" to map to it's id. You can fetch all rows together from the DB, as one Row object, using a join. For example:

SELECT item1.id AS item2_id, item1.val AS item1_val,
               item2.id AS item2_id, item2.val AS item2_val
               FROM item1 LEFT JOIN item2 ON (item2.id = item1.item2_id)

But now, I cannot use the nice init function which takes a row to construct them, I have to use normal construction fetching the correctly named fields.

An adapter may be useful here, for example:

var adapter = ["id" : "item2_id", "val" : "item2_val"]
let item2 = Item2(row, withAdapter: adapter) // proposed usage?

Alternatively, you could make a Row constructor that uses another Row as backing with the adapter on top.

Error "missing statement argument(s)"

I am getting this error on statement.swift line 226
throw DatabaseError(code: SQLITE_MISUSE, message: "missing statement argument(s): (caseInsensitiveSort(namedMissingKeys).joinWithSeparator(", "))", sql: sql, arguments: nil)

EXC_BAD_ACCESS on initialization

in DatabaseQueue.init():

        try self.init(database: Database(path: path, configuration: configuration))

results in EXC_BAD_ACCESS (code=EXC_i386_GPFLT)

code in my ViewController looks like this:

class ViewController: UIViewController,CLLocationManagerDelegate {
    var dbQueue: AnyObject?
    override func viewDidLoad() {
        do {
            dbQueue = try DatabaseQueue(path: "/db.sqlite")
        } catch {
            print("Error opening SQLite Database")
        }

Any ideas on working around this?

issue with path

after the last update the app return me: fatal error:
"unexpectedly found nil while unwrapping an Optional value"

func trovaCitta(luogoNascita: String)->CittaVO{

    let citta:CittaVO = CittaVO()


    let databasePath = NSBundle.mainBundle().pathForResource("mydb", ofType: "sqlite")!
    let dbQueue = try! DatabaseQueue(path: databasePath)

    dbQueue.inDatabase { db in

        for row in Row.fetch(db, "SELECT nome, cod_istat FROM comune where cod_catastale='" + luogoNascita + "'") {
            citta.nome = row.value(named: "nome")
            citta.codIstat = row.value(named: "cod_istat")
          //  print(citta)
        }

    }

    return citta
}

the app crash on let dbQueue = try! DatabaseQueue(path: databasePath)

can you help me please? maybe I'm wrong something. thanks

Database not on the correct thread ...

Sorry this is a little complicated ... I need to do a select from a couple of tables in one database and insert them into another. I'd like to do this in a transaction. At the moment my code is not doing that.
I have nested dbQueue (different) and this is causing a problem ...
Any sugestions please?

dbQueueMerge = source databaase
dbQueue = destination database

let dbQueueMerge = try! DatabaseQueue(path: url.path!, configuration: config)
        dbQueue.inDatabase { db in
            try! dbQueueMerge.inDatabase {dbMerge in
                for groupRow in Row.fetch(dbMerge, "SELECT * FROM groups") {
                    var newid: Int64 = 0
                    let groupid: Int64 = groupRow.value(named: "groupid")
                    let name: String = groupRow.value(named: "name")
                    let description: String = groupRow.value(named: "description")
                    try db.execute("INSERT INTO groups (name, description) VALUES (?, ?)",                       arguments: [name, description])
                    newid = db.lastInsertedRowID
                    for wordRow in Row.fetch(dbMerge, "SELECT * FROM words WHERE groupid = \(groupid)") {
                        let word: String = wordRow.value(named: "word")
                        let action: String = wordRow.value(named: "action")
                        try db.execute("INSERT INTO words (groupid, word, action) VALUES (?, ?, ?)",
                            arguments: [newid, word, action])
                    }
                }
            }
        }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.