carray-io-sqlite3 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e722c2d367cef2bdae609adcf1fce39eb8b56e32066af328cc96ad2490ab5e2
4
- data.tar.gz: f8f1f3d262970cbe8c907ff2a7499256a1f3c414e974433ec5148e08171565e8
3
+ metadata.gz: 1314c190f90f50800ec969287e33214b64c7492ae4541027c92e6bb95dba19f5
4
+ data.tar.gz: 7d9cdd018be9407fe1d5c8ff78d0c7529551478a369b15f5a8c48daf2f7dbe36
5
5
  SHA512:
6
- metadata.gz: a41bc8f66e79e508e2faba02e933a1eff01f65079a8e7130fa1ef1427932cefed78a2902bf3b00b3dddd477935731056e9d759c279d9e6cbf76486e789fbdeec
7
- data.tar.gz: bd001891dc3018bcf0c1bdba84edbc92ad20619dfd37d7d537ab44b984d5bedab7c2669aea0894825695e2945cb733c558b15cd8952de9f8f0f71ca4d06871fa
6
+ metadata.gz: 5e26cd252361633fa52d7ee0c2e8e5b9039783378e70bb6a913c47971b41ecfd0f3a81f7886303dd125575f30d6da0248b3c097fdccf37f05f7521e75cade3d3
7
+ data.tar.gz: 2ee64698ac7e9e4e44e2a64bb535376573aa9f200cb188991c8181b821f4ed8578f29a65042861b8109418c9a5d70f147cd816f0e3bc74732e74842ae46f3ab8
@@ -1,5 +1,5 @@
1
1
  Gem::Specification::new do |s|
2
- version = "0.9.2"
2
+ version = "0.9.3"
3
3
  files = Dir.glob("**/*") - [
4
4
  Dir.glob("carray-io-sqlite3-*.gem"),
5
5
  Dir.glob("test/**/*"),
@@ -23,12 +23,12 @@ class CArray
23
23
  raise "invalid 1st arg"
24
24
  end
25
25
  table = table.to_ca
26
- table.extend(CA::TableMethods)
26
+ table.extend(CArray::TableMethods)
27
27
  table.column_names = names
28
28
  return table
29
29
  end
30
30
 
31
- def to_sqlite3 (database: nil, table:, datatype: "numeric", schema: nil, transaction: true)
31
+ def to_sqlite3 (database: nil, table:, datatype: "numeric", schema: nil, transaction: true, primary_key: nil)
32
32
  unless rank <= 2
33
33
  raise "to_sqlite3 is valid only for 2-dim array (table)"
34
34
  end
@@ -56,28 +56,40 @@ class CArray
56
56
  if schema
57
57
  database.execute "create table if not exists #{table} (" + schema + ")"
58
58
  else
59
- database.execute "create table if not exists #{table} (" + vars.map{|s| s + " " + datatype }.join(",") + ")"
59
+ constraints = []
60
+ case primary_key
61
+ when String
62
+ constraints << "primary key (#{primary_key})"
63
+ when Array
64
+ constraints << "primary key (#{primary_key.join(",")})"
65
+ end
66
+ entries = vars.map{|s| s + " " + datatype } + constraints
67
+ database.execute "create table if not exists #{table} (" + entries.join(",") + ")"
60
68
  end
61
69
 
62
70
  insert = database.prepare %{ insert or replace into #{table} values (#{(["?"]*vars.size).join(",")}) }
63
- database.transaction if transaction
64
- if rank == 1
65
- dim0.times do |i|
66
- insert.execute [self[i]]
67
- end
68
- else
69
- begin
71
+ begin
72
+ database.transaction if transaction
73
+ if rank == 1
70
74
  dim0.times do |i|
71
- begin
72
- insert.execute self[i,nil].to_a
73
- rescue
74
- puts self[i,nil].to_a
75
- raise $!
75
+ insert.execute [self[i]]
76
+ end
77
+ else
78
+ out = self.object.unmask("null")
79
+ begin
80
+ dim0.times do |i|
81
+ begin
82
+ insert.execute out[i,nil].to_a
83
+ rescue
84
+ puts out[i,nil].to_a.inspect
85
+ raise $!
86
+ end
76
87
  end
77
88
  end
78
89
  end
90
+ ensure
91
+ database.commit if transaction
79
92
  end
80
- database.commit if transaction
81
93
  insert.close
82
94
  return database
83
95
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carray-io-sqlite3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroki Motoyoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-08 00:00:00.000000000 Z
11
+ date: 2021-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carray