mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Open a database
This commit is contained in:
1 parent
7a6675386b
commit
0ac4dce2ef
8 files changed
+122
-6
No files matched your search
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// DatabaseTests.swift
|
||||
// GRDB
|
||||
//
|
||||
// Created by Gwendal Roué on 30/06/2015.
|
||||
// Copyright © 2015 Stephen Celis. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import GRDB
|
||||
|
||||
class DatabaseTests: XCTestCase {
|
||||
|
||||
func testDatabase() {
|
||||
do {
|
||||
let database = try Database(path: "/tmp/GRDB.sqlite")
|
||||
} catch {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.github.groue.$(PRODUCT_NAME:rfc1034identifier)</string>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
565E191E1B42B2B600D32814 /* Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565E191D1B42B2B600D32814 /* Database.swift */; };
|
||||
565E19201B42B9C000D32814 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565E191F1B42B9C000D32814 /* Error.swift */; };
|
||||
5699AE551B42BE8700C35172 /* DatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5699AE541B42BE8700C35172 /* DatabaseTests.swift */; };
|
||||
DC2393C81ABE35F8003FF113 /* GRDB-Bridging.h in Headers */ = {isa = PBXBuildFile; fileRef = DC2393C61ABE35F8003FF113 /* GRDB-Bridging.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
DC2F675E1AEA7CD600151C15 /* fts3_tokenizer.h in Headers */ = {isa = PBXBuildFile; fileRef = DC2F675D1AEA7CD600151C15 /* fts3_tokenizer.h */; };
|
||||
DC3773F919C8CBB3004FCF85 /* GRDB.h in Headers */ = {isa = PBXBuildFile; fileRef = DC3773F819C8CBB3004FCF85 /* GRDB.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
@@ -25,6 +28,9 @@
|
||||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
565E191D1B42B2B600D32814 /* Database.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Database.swift; sourceTree = "<group>"; };
|
||||
565E191F1B42B9C000D32814 /* Error.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Error.swift; sourceTree = "<group>"; };
|
||||
5699AE541B42BE8700C35172 /* DatabaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseTests.swift; sourceTree = "<group>"; };
|
||||
DC2393C61ABE35F8003FF113 /* GRDB-Bridging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GRDB-Bridging.h"; sourceTree = "<group>"; };
|
||||
DC2F675D1AEA7CD600151C15 /* fts3_tokenizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fts3_tokenizer.h; sourceTree = "<group>"; };
|
||||
DC3773F319C8CBB3004FCF85 /* GRDB.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = GRDB.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
@@ -61,6 +67,7 @@
|
||||
DC10500F19C904DD00D8CA30 /* GRDB Tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
5699AE541B42BE8700C35172 /* DatabaseTests.swift */,
|
||||
DC37740319C8CBB3004FCF85 /* Supporting Files */,
|
||||
);
|
||||
path = "GRDB Tests";
|
||||
@@ -100,6 +107,8 @@
|
||||
DC37742D19C8CC90004FCF85 /* GRDB */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
565E191D1B42B2B600D32814 /* Database.swift */,
|
||||
565E191F1B42B9C000D32814 /* Error.swift */,
|
||||
DC37743319C8CFCE004FCF85 /* Supporting Files */,
|
||||
);
|
||||
path = GRDB;
|
||||
@@ -177,7 +186,8 @@
|
||||
DC3773EA19C8CBB3004FCF85 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastUpgradeCheck = 0640;
|
||||
LastSwiftUpdateCheck = 0700;
|
||||
LastUpgradeCheck = 0700;
|
||||
ORGANIZATIONNAME = "Stephen Celis";
|
||||
TargetAttributes = {
|
||||
DC3773F219C8CBB3004FCF85 = {
|
||||
@@ -228,6 +238,8 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
565E19201B42B9C000D32814 /* Error.swift in Sources */,
|
||||
565E191E1B42B2B600D32814 /* Database.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -235,6 +247,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
5699AE551B42BE8700C35172 /* DatabaseTests.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -269,6 +282,7 @@
|
||||
COPY_PHASE_STRIP = NO;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
@@ -331,6 +345,7 @@
|
||||
baseConfigurationReference = DC37742E19C8CE67004FCF85 /* GRDB.xcconfig */;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
@@ -338,6 +353,7 @@
|
||||
INFOPLIST_FILE = GRDB/Info.plist;
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.github.groue.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
@@ -349,6 +365,7 @@
|
||||
baseConfigurationReference = DC37742E19C8CE67004FCF85 /* GRDB.xcconfig */;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
@@ -356,6 +373,7 @@
|
||||
INFOPLIST_FILE = GRDB/Info.plist;
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.github.groue.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
};
|
||||
@@ -366,9 +384,14 @@
|
||||
baseConfigurationReference = DC37742E19C8CE67004FCF85 /* GRDB.xcconfig */;
|
||||
buildSettings = {
|
||||
APPLICATION_EXTENSION_API_ONLY = NO;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
|
||||
INFOPLIST_FILE = "GRDB Tests/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.github.groue.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_WHOLE_MODULE_OPTIMIZATION = NO;
|
||||
};
|
||||
name = Debug;
|
||||
@@ -378,7 +401,11 @@
|
||||
baseConfigurationReference = DC37742E19C8CE67004FCF85 /* GRDB.xcconfig */;
|
||||
buildSettings = {
|
||||
APPLICATION_EXTENSION_API_ONLY = NO;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
INFOPLIST_FILE = "GRDB Tests/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.github.groue.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_WHOLE_MODULE_OPTIMIZATION = NO;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0640"
|
||||
LastUpgradeVersion = "0700"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
@@ -22,7 +22,7 @@
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForRunning = "NO"
|
||||
buildForProfiling = "NO"
|
||||
buildForArchiving = "NO"
|
||||
buildForAnalyzing = "YES">
|
||||
@@ -62,6 +62,8 @@
|
||||
ReferencedContainer = "container:GRDB.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
@@ -71,6 +73,7 @@
|
||||
buildConfiguration = "Debug"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Database.swift
|
||||
// GRDB
|
||||
//
|
||||
// Created by Gwendal Roué on 30/06/2015.
|
||||
// Copyright © 2015 Stephen Celis. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
typealias CDatabase = COpaquePointer
|
||||
|
||||
public class Database {
|
||||
let cDB = CDatabase()
|
||||
|
||||
public init(path: String) throws {
|
||||
let code = path.nulTerminatedUTF8.withUnsafeBufferPointer { codeUnits in
|
||||
sqlite3_open(UnsafePointer<Int8>(codeUnits.baseAddress), &cDB)
|
||||
}
|
||||
try Error.checkCResultCode(code, cDB: cDB)
|
||||
}
|
||||
|
||||
deinit {
|
||||
if cDB != nil {
|
||||
sqlite3_close(cDB)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// Error.swift
|
||||
// GRDB
|
||||
//
|
||||
// Created by Gwendal Roué on 30/06/2015.
|
||||
// Copyright © 2015 Stephen Celis. All rights reserved.
|
||||
//
|
||||
|
||||
struct Error : ErrorType {
|
||||
let _domain: String = "GRDB.Error"
|
||||
let _code: Int
|
||||
let message: String?
|
||||
|
||||
init(code: Int32, message: String? = nil) {
|
||||
self._code = Int(code)
|
||||
self.message = message
|
||||
}
|
||||
|
||||
static func checkCResultCode(code: Int32, cDB: CDatabase) throws {
|
||||
if code != SQLITE_OK {
|
||||
let message: String?
|
||||
let cstring = sqlite3_errmsg(cDB)
|
||||
if cstring == nil {
|
||||
message = nil
|
||||
} else {
|
||||
message = String.fromCString(cstring)
|
||||
}
|
||||
throw Error(code: code, message: message)
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.github.groue.$(PRODUCT_NAME:rfc1034identifier)</string>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
|
||||
Reference in new issue
Block a user