motion-sqlite3 0.5.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +22 -1
- data/LICENSE +7 -0
- data/README.md +1 -5
- data/Rakefile +4 -9
- data/lib/motion-sqlite3.rb +1 -1
- data/lib/motion-sqlite3/database.rb +3 -3
- data/lib/motion-sqlite3/result_set.rb +10 -24
- data/lib/motion-sqlite3/statement.rb +13 -13
- data/lib/motion-sqlite3/version.rb +1 -1
- data/motion-sqlite3.gemspec +2 -2
- data/spec/database_spec.rb +14 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b019eb6013a8396a0d422ffd1f5eafeb13a580c4f3d30f0e3dc118188b9f6c97
|
4
|
+
data.tar.gz: cb3fcf49b7145ef755eec8756afd78b6cc6c967e735dfacecbbba6d0eadcc590
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a031759f1f4b2724454dd435c29c4eb4cc1b9b6ca009121b7f5891552dbcade4a2f043e3a49bf112ab8310d17885555b983e0e59628144a9a7e1a6c6843b203a
|
7
|
+
data.tar.gz: 3d9f5eeefa0b0e4e7578bf55be7e75ccaf290140a730c6a8117e7cf11844d27118034c63b45ef907b23df2a91406c0365880dd92d349a42aaea2601c31092b3a
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,2 +1,23 @@
|
|
1
|
-
install: bundle install
|
2
1
|
language: objective-c
|
2
|
+
osx_image: xcode12.4
|
3
|
+
env:
|
4
|
+
global:
|
5
|
+
- RUBYMOTION_LICENSE=1dcac45cc434293009f74b33037bdf7361a3a1ff # Official license key for open-source projects
|
6
|
+
- TMP_DIR=./tmp # For motion repo, so it doesn't attempt to use /tmp, to which it has no access
|
7
|
+
- OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
|
8
|
+
before_install:
|
9
|
+
- brew update
|
10
|
+
- brew outdated xctool || brew upgrade xctool
|
11
|
+
- (xcrun simctl list)
|
12
|
+
- wget http://travisci.rubymotion.com/ -O RubyMotion-TravisCI.pkg
|
13
|
+
- sudo installer -pkg RubyMotion-TravisCI.pkg -target /
|
14
|
+
- cp -r /usr/lib/swift/*.dylib /Applications/Xcode.app/Contents/Frameworks/
|
15
|
+
- touch /Applications/Xcode.app/Contents/Frameworks/.swift-5-staged
|
16
|
+
- sudo mkdir -p ~/Library/RubyMotion/build
|
17
|
+
- sudo chown -R travis ~/Library/RubyMotion
|
18
|
+
- eval "sudo motion activate $RUBYMOTION_LICENSE"
|
19
|
+
- sudo motion update
|
20
|
+
- (motion --version)
|
21
|
+
- (ruby --version)
|
22
|
+
- motion repo
|
23
|
+
script: bundle exec rake spec
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2013-2014 Matt Green
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ This is a tiny wrapper around the SQLite C API that's written in RubyMotion. It
|
|
4
4
|
|
5
5
|
Whenever possible, it uses Ruby idioms like blocks and exceptions.
|
6
6
|
|
7
|
-
[![Code Climate](https://codeclimate.com/github/
|
7
|
+
[![Code Climate](https://codeclimate.com/github/rubymotion-community/motion-sqlite3.png)](https://codeclimate.com/github/rubymotion-community/motion-sqlite3) [![Build Status](https://travis-ci.org/rubymotion-community/motion-sqlite3.png?branch=master)](https://travis-ci.org/rubymotion-community/motion-sqlite3) [![Gem Version](https://badge.fury.io/rb/motion-sqlite3.png)](http://badge.fury.io/rb/motion-sqlite3)
|
8
8
|
|
9
9
|
Is it any good?
|
10
10
|
---------------
|
@@ -52,7 +52,3 @@ Usage
|
|
52
52
|
* Use `execute` to run SQL statements. All SQL statements are first prepared, and parameters can be passed as an Array or a Hash. If a Hash is passed, then the SQLite named parameter syntax is assumed to be in use.
|
53
53
|
* Use `execute_debug` to see the SQL statement and paramaters passed in the REPL. You should not use this method in production.
|
54
54
|
* Use `execute_scalar` to run SQL statements and return the first column of the first row. This is useful for queries like `SELECT COUNT(*) FROM posts`.
|
55
|
-
|
56
|
-
Status
|
57
|
-
----------
|
58
|
-
Still in early stages. I'm hacking on it.
|
data/Rakefile
CHANGED
@@ -1,21 +1,16 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
$:.unshift("/Library/RubyMotion/lib")
|
3
|
-
|
3
|
+
$:.unshift("~/.rubymotion/rubymotion-templates")
|
4
4
|
|
5
|
-
require "
|
5
|
+
require "motion/project/template/ios"
|
6
|
+
require "motion/project/template/gem/gem_tasks"
|
6
7
|
require "bundler/setup"
|
7
|
-
Bundler.require
|
8
|
+
Bundler.require
|
8
9
|
|
9
10
|
Motion::Project::App.setup do |app|
|
10
11
|
app.name = 'motion-sqlite3'
|
11
12
|
|
12
|
-
base_dir = File.dirname(__FILE__)
|
13
|
-
app.files += Dir.glob(File.join(base_dir, "lib/motion-sqlite3/**/*.rb"))
|
14
|
-
|
15
13
|
if ENV["DEFAULT_PROVISIONING_PROFILE"]
|
16
14
|
app.provisioning_profile = ENV["DEFAULT_PROVISIONING_PROFILE"]
|
17
15
|
end
|
18
|
-
|
19
|
-
app.libs << "/usr/lib/libsqlite3.dylib"
|
20
|
-
app.include 'sqlite3.h'
|
21
16
|
end
|
data/lib/motion-sqlite3.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
module SQLite3
|
2
2
|
class Database
|
3
|
+
attr_accessor :logging
|
4
|
+
|
3
5
|
def initialize(filename)
|
4
6
|
@handle = Pointer.new(::Sqlite3.type)
|
5
7
|
@logging = false
|
6
8
|
|
7
9
|
result = sqlite3_open(filename, @handle)
|
8
|
-
raise SQLite3Error, sqlite3_errmsg(@handle.
|
10
|
+
raise SQLite3Error, sqlite3_errmsg(@handle.value_with_autorelease) if result != SQLITE_OK
|
9
11
|
end
|
10
12
|
|
11
13
|
def execute(sql, params = nil, &block)
|
@@ -39,8 +41,6 @@ module SQLite3
|
|
39
41
|
execute(*args).first.values.first
|
40
42
|
end
|
41
43
|
|
42
|
-
attr_accessor :logging
|
43
|
-
|
44
44
|
def transaction(&block)
|
45
45
|
execute("BEGIN TRANSACTION")
|
46
46
|
|
@@ -15,43 +15,29 @@ module SQLite3
|
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
def columns
|
19
|
-
@result_columns ||= begin
|
20
|
-
columns = {}
|
21
|
-
|
22
|
-
count = sqlite3_column_count(@handle.value)
|
23
|
-
0.upto(count-1) do |i|
|
24
|
-
name = sqlite3_column_name(@handle.value, i).to_sym
|
25
|
-
type = sqlite3_column_type(@handle.value, i)
|
26
|
-
|
27
|
-
columns[name] = ColumnMetadata.new(i, type)
|
28
|
-
end
|
29
|
-
|
30
|
-
columns
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
18
|
def current_row
|
35
19
|
row = {}
|
36
20
|
|
37
|
-
|
38
|
-
|
21
|
+
column_count = sqlite3_column_count(@handle.value_with_autorelease)
|
22
|
+
0.upto(column_count - 1) do |i|
|
23
|
+
name = sqlite3_column_name(@handle.value_with_autorelease, i).to_sym
|
24
|
+
type = sqlite3_column_type(@handle.value_with_autorelease, i)
|
25
|
+
|
26
|
+
case type
|
39
27
|
when SQLITE_NULL
|
40
28
|
row[name] = nil
|
41
29
|
when SQLITE_TEXT
|
42
|
-
row[name] = sqlite3_column_text(@handle.
|
30
|
+
row[name] = sqlite3_column_text(@handle.value_with_autorelease, i)
|
43
31
|
when SQLITE_BLOB
|
44
|
-
row[name] = NSData.dataWithBytes(sqlite3_column_blob(@handle.
|
32
|
+
row[name] = NSData.dataWithBytes(sqlite3_column_blob(@handle.value_with_autorelease, i), length: sqlite3_column_bytes(@handle.value_with_autorelease, i))
|
45
33
|
when SQLITE_INTEGER
|
46
|
-
row[name] =
|
34
|
+
row[name] = sqlite3_column_int64(@handle.value_with_autorelease, i)
|
47
35
|
when SQLITE_FLOAT
|
48
|
-
row[name] = sqlite3_column_double(@handle.
|
36
|
+
row[name] = sqlite3_column_double(@handle.value_with_autorelease, i)
|
49
37
|
end
|
50
38
|
end
|
51
39
|
|
52
40
|
row
|
53
41
|
end
|
54
42
|
end
|
55
|
-
|
56
|
-
class ColumnMetadata < Struct.new(:index, :type); end
|
57
43
|
end
|
@@ -20,13 +20,13 @@ module SQLite3
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def finalize
|
23
|
-
sqlite3_finalize(@handle.
|
23
|
+
sqlite3_finalize(@handle.value_with_autorelease)
|
24
24
|
end
|
25
25
|
|
26
26
|
def step
|
27
|
-
@result = sqlite3_step(@handle.
|
27
|
+
@result = sqlite3_step(@handle.value_with_autorelease)
|
28
28
|
unless @result == SQLITE_DONE || @result == SQLITE_ROW
|
29
|
-
raise SQLite3Error, sqlite3_errmsg(@db.
|
29
|
+
raise SQLite3Error, sqlite3_errmsg(@db.value_with_autorelease)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -49,20 +49,20 @@ module SQLite3
|
|
49
49
|
|
50
50
|
case value
|
51
51
|
when NilClass
|
52
|
-
result = sqlite3_bind_null(@handle.
|
52
|
+
result = sqlite3_bind_null(@handle.value_with_autorelease, index)
|
53
53
|
when String, Symbol
|
54
|
-
result = sqlite3_bind_text(@handle.
|
54
|
+
result = sqlite3_bind_text(@handle.value_with_autorelease, index, value, -1, lambda { |arg| })
|
55
55
|
when Integer
|
56
|
-
result =
|
56
|
+
result = sqlite3_bind_int64(@handle.value_with_autorelease, index, value)
|
57
57
|
when Float
|
58
|
-
result = sqlite3_bind_double(@handle.
|
59
|
-
when
|
60
|
-
result = sqlite3_bind_blob(@handle.
|
58
|
+
result = sqlite3_bind_double(@handle.value_with_autorelease, index, value)
|
59
|
+
when NSDatavalue
|
60
|
+
result = sqlite3_bind_blob(@handle.value_with_autorelease, index, value.bytes, value.length, lambda { |arg| })
|
61
61
|
else
|
62
62
|
raise SQLite3Error, "unable to bind #{value} to #{name}: unexpected type #{value.class}"
|
63
63
|
end
|
64
64
|
|
65
|
-
raise SQLite3Error, sqlite3_errmsg(@db.
|
65
|
+
raise SQLite3Error, sqlite3_errmsg(@db.value_with_autorelease) if result != SQLITE_OK
|
66
66
|
end
|
67
67
|
|
68
68
|
def column_index(name)
|
@@ -70,7 +70,7 @@ module SQLite3
|
|
70
70
|
|
71
71
|
case name
|
72
72
|
when String, Symbol
|
73
|
-
index = sqlite3_bind_parameter_index(@handle.
|
73
|
+
index = sqlite3_bind_parameter_index(@handle.value_with_autorelease, ":#{name}")
|
74
74
|
raise SQLite3Error, "couldn't find index for #{name}!" if index == 0
|
75
75
|
|
76
76
|
when Integer
|
@@ -82,8 +82,8 @@ module SQLite3
|
|
82
82
|
|
83
83
|
def prepare(sql)
|
84
84
|
remainder = Pointer.new(:string)
|
85
|
-
result = sqlite3_prepare_v2(@db.
|
86
|
-
raise SQLite3Error, sqlite3_errmsg(@db.
|
85
|
+
result = sqlite3_prepare_v2(@db.value_with_autorelease, sql, -1, @handle, remainder)
|
86
|
+
raise SQLite3Error, sqlite3_errmsg(@db.value_with_autorelease) if result != SQLITE_OK
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
data/motion-sqlite3.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.description = "A minimal wrapper over the SQLite 3 C API for RubyMotion"
|
8
8
|
gem.summary = "A minimal wrapper over the SQLite 3 C API for RubyMotion"
|
9
9
|
gem.license = "MIT"
|
10
|
-
gem.homepage = "http://github.com/
|
10
|
+
gem.homepage = "http://github.com/rubymotion-community/motion-sqlite3"
|
11
11
|
|
12
12
|
gem.files = `git ls-files`.split($\)
|
13
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
@@ -16,5 +16,5 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.version = SQLite3::VERSION
|
17
17
|
|
18
18
|
gem.add_development_dependency 'rake'
|
19
|
-
gem.add_dependency 'motion.h', '~> 0.0.
|
19
|
+
gem.add_dependency 'motion.h', '~> 0.0.6'
|
20
20
|
end
|
data/spec/database_spec.rb
CHANGED
@@ -24,7 +24,7 @@ describe SQLite3::Database do
|
|
24
24
|
@db.execute("INSERT INTO test VALUES(:name, :address)", { name: "matt", address: "123 main st" })
|
25
25
|
|
26
26
|
@db.execute_scalar("SELECT changes()").should == 1
|
27
|
-
end
|
27
|
+
end
|
28
28
|
|
29
29
|
it "returns rows if no block is provided" do
|
30
30
|
@db.execute("CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER)")
|
@@ -52,6 +52,19 @@ describe SQLite3::Database do
|
|
52
52
|
{ id: 2, name: "sparky", age: 24 }
|
53
53
|
]
|
54
54
|
end
|
55
|
+
|
56
|
+
it "handles results where the first row has a nil column correctly" do
|
57
|
+
@db.execute 'create virtual table fts_1 using fts4 (col_1, col_2)'
|
58
|
+
@db.execute "insert into fts_1 (col_1) values ('hello')"
|
59
|
+
@db.execute "insert into fts_1 (col_2) values ('hello')"
|
60
|
+
|
61
|
+
rows = @db.execute("select col_1, col_2 from fts_1 where fts_1 match 'hello' order by rowid")
|
62
|
+
rows.size.should == 2
|
63
|
+
one, two = rows
|
64
|
+
|
65
|
+
one.should == { col_1: 'hello', col_2: nil }
|
66
|
+
two.should == { col_1: nil, col_2: 'hello' }
|
67
|
+
end
|
55
68
|
end
|
56
69
|
|
57
70
|
describe "#execute_scalar" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-sqlite3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Green
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.0.
|
33
|
+
version: 0.0.6
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.0.
|
40
|
+
version: 0.0.6
|
41
41
|
description: A minimal wrapper over the SQLite 3 C API for RubyMotion
|
42
42
|
email:
|
43
43
|
- mattgreenrocks@gmail.com
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- ".travis.yml"
|
50
50
|
- Gemfile
|
51
51
|
- Guardfile
|
52
|
+
- LICENSE
|
52
53
|
- README.md
|
53
54
|
- Rakefile
|
54
55
|
- app/app_delegate.rb
|
@@ -60,7 +61,7 @@ files:
|
|
60
61
|
- lib/motion-sqlite3/version.rb
|
61
62
|
- motion-sqlite3.gemspec
|
62
63
|
- spec/database_spec.rb
|
63
|
-
homepage: http://github.com/
|
64
|
+
homepage: http://github.com/rubymotion-community/motion-sqlite3
|
64
65
|
licenses:
|
65
66
|
- MIT
|
66
67
|
metadata: {}
|
@@ -79,8 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
80
|
- !ruby/object:Gem::Version
|
80
81
|
version: '0'
|
81
82
|
requirements: []
|
82
|
-
|
83
|
-
rubygems_version: 2.2.0
|
83
|
+
rubygems_version: 3.1.2
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: A minimal wrapper over the SQLite 3 C API for RubyMotion
|