bson_ext 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ #include <stdlib.h>
2
+
3
+ #define ASSERT(x) \
4
+ do{ \
5
+ if(!(x)){ \
6
+ printf("failed assert (%d): %s\n", __LINE__, #x); \
7
+ exit(1); \
8
+ }\
9
+ }while(0)
10
+
11
+ #ifdef _WIN32
12
+ #define INIT_SOCKETS_FOR_WINDOWS \
13
+ do{ \
14
+ WSADATA out; \
15
+ WSAStartup(MAKEWORD(2,2), &out); \
16
+ } while(0)
17
+ #else
18
+ #define INIT_SOCKETS_FOR_WINDOWS do {} while(0)
19
+ #endif
@@ -0,0 +1,107 @@
1
+ #include "test.h"
2
+ #include "mongo.h"
3
+ #include <stdio.h>
4
+ #include <string.h>
5
+ #include <stdlib.h>
6
+
7
+ int main(){
8
+ mongo_connection conn[1];
9
+ bson_buffer bb;
10
+ bson obj;
11
+ bson cond;
12
+ int i;
13
+ bson_oid_t oid;
14
+ const char* col = "c.update_test";
15
+ const char* ns = "test.c.update_test";
16
+
17
+ INIT_SOCKETS_FOR_WINDOWS;
18
+
19
+ if (mongo_connect( conn , TEST_SERVER, 27017 )){
20
+ printf("failed to connect\n");
21
+ exit(1);
22
+ }
23
+
24
+ /* if the collection doesn't exist dropping it will fail */
25
+ if (!mongo_cmd_drop_collection(conn, "test", col, NULL)
26
+ && mongo_find_one(conn, ns, bson_empty(&obj), bson_empty(&obj), NULL)){
27
+ printf("failed to drop collection\n");
28
+ exit(1);
29
+ }
30
+
31
+ bson_oid_gen(&oid);
32
+
33
+ { /* insert */
34
+ bson_buffer_init(&bb);
35
+ bson_append_oid(&bb, "_id", &oid);
36
+ bson_append_int(&bb, "a", 3 );
37
+ bson_from_buffer(&obj, &bb);
38
+ mongo_insert(conn, ns, &obj);
39
+ bson_destroy(&obj);
40
+ }
41
+
42
+ { /* insert */
43
+ bson op;
44
+
45
+ bson_buffer_init(&bb);
46
+ bson_append_oid(&bb, "_id", &oid);
47
+ bson_from_buffer(&cond, &bb);
48
+
49
+ bson_buffer_init(&bb);
50
+ {
51
+ bson_buffer * sub = bson_append_start_object(&bb, "$inc");
52
+ bson_append_int(sub, "a", 2 );
53
+ bson_append_finish_object(sub);
54
+ }
55
+ {
56
+ bson_buffer * sub = bson_append_start_object(&bb, "$set");
57
+ bson_append_double(sub, "b", -1.5 );
58
+ bson_append_finish_object(sub);
59
+ }
60
+ bson_from_buffer(&op, &bb);
61
+
62
+ for (i=0; i<5; i++)
63
+ mongo_update(conn, ns, &cond, &op, 0);
64
+
65
+ /* cond is used later */
66
+ bson_destroy(&op);
67
+ }
68
+
69
+ if(!mongo_find_one(conn, ns, &cond, 0, &obj)){
70
+ printf("Failed to find object\n");
71
+ exit(1);
72
+ } else {
73
+ int fields = 0;
74
+ bson_iterator it;
75
+ bson_iterator_init(&it, obj.data);
76
+
77
+ bson_destroy(&cond);
78
+
79
+ while(bson_iterator_next(&it)){
80
+ switch(bson_iterator_key(&it)[0]){
81
+ case '_': /* id */
82
+ ASSERT(bson_iterator_type(&it) == bson_oid);
83
+ ASSERT(!memcmp(bson_iterator_oid(&it)->bytes, oid.bytes, 12));
84
+ fields++;
85
+ break;
86
+ case 'a':
87
+ ASSERT(bson_iterator_type(&it) == bson_int);
88
+ ASSERT(bson_iterator_int(&it) == 3 + 5*2);
89
+ fields++;
90
+ break;
91
+ case 'b':
92
+ ASSERT(bson_iterator_type(&it) == bson_double);
93
+ ASSERT(bson_iterator_double(&it) == -1.5);
94
+ fields++;
95
+ break;
96
+ }
97
+ }
98
+
99
+ ASSERT(fields == 3);
100
+ }
101
+
102
+ bson_destroy(&obj);
103
+
104
+ mongo_cmd_drop_db(conn, "test");
105
+ mongo_destroy(conn);
106
+ return 0;
107
+ }
metadata CHANGED
@@ -1,20 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bson_ext
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 7
5
+ prerelease:
5
6
  segments:
6
- - 1
7
- - 3
8
- - 1
9
- version: 1.3.1
7
+ - 1
8
+ - 4
9
+ - 0
10
+ version: 1.4.0
10
11
  platform: ruby
11
12
  authors:
12
- - Mike Dirolf
13
+ - Mike Dirolf
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-05-11 00:00:00 -04:00
18
+ date: 2011-09-20 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies: []
20
21
 
@@ -23,19 +24,46 @@ email: mongodb-dev@googlegroups.com
23
24
  executables: []
24
25
 
25
26
  extensions:
26
- - ext/cbson/extconf.rb
27
+ - ext/cbson/extconf.rb
27
28
  extra_rdoc_files: []
28
29
 
29
30
  files:
30
- - Rakefile
31
- - bson_ext.gemspec
32
- - ext/cbson/extconf.rb
33
- - ext/cbson/encoding_helpers.c
34
- - ext/cbson/buffer.c
35
- - ext/cbson/cbson.c
36
- - ext/cbson/encoding_helpers.h
37
- - ext/cbson/version.h
38
- - ext/cbson/buffer.h
31
+ - Rakefile
32
+ - bson_ext.gemspec
33
+ - ext/cbson/extconf.rb
34
+ - ext/cbson/bson_buffer.c
35
+ - ext/cbson/cbson.c
36
+ - ext/cbson/encoding_helpers.c
37
+ - ext/cmongo/c-driver/src/bson.c
38
+ - ext/cmongo/c-driver/src/gridfs.c
39
+ - ext/cmongo/c-driver/src/md5.c
40
+ - ext/cmongo/c-driver/src/mongo.c
41
+ - ext/cmongo/c-driver/src/numbers.c
42
+ - ext/cmongo/c-driver/test/all_types.c
43
+ - ext/cmongo/c-driver/test/auth.c
44
+ - ext/cmongo/c-driver/test/benchmark.c
45
+ - ext/cmongo/c-driver/test/count_delete.c
46
+ - ext/cmongo/c-driver/test/endian_swap.c
47
+ - ext/cmongo/c-driver/test/errors.c
48
+ - ext/cmongo/c-driver/test/examples.c
49
+ - ext/cmongo/c-driver/test/gridfs.c
50
+ - ext/cmongo/c-driver/test/json.c
51
+ - ext/cmongo/c-driver/test/pair.c
52
+ - ext/cmongo/c-driver/test/replica_set.c
53
+ - ext/cmongo/c-driver/test/resize.c
54
+ - ext/cmongo/c-driver/test/simple.c
55
+ - ext/cmongo/c-driver/test/sizes.c
56
+ - ext/cmongo/c-driver/test/update.c
57
+ - ext/cbson/bson_buffer.h
58
+ - ext/cbson/encoding_helpers.h
59
+ - ext/cbson/version.h
60
+ - ext/cmongo/c-driver/src/bson.h
61
+ - ext/cmongo/c-driver/src/gridfs.h
62
+ - ext/cmongo/c-driver/src/md5.h
63
+ - ext/cmongo/c-driver/src/mongo.h
64
+ - ext/cmongo/c-driver/src/mongo_except.h
65
+ - ext/cmongo/c-driver/src/platform_hacks.h
66
+ - ext/cmongo/c-driver/test/test.h
39
67
  has_rdoc: true
40
68
  homepage: http://www.mongodb.org
41
69
  licenses: []
@@ -44,25 +72,29 @@ post_install_message:
44
72
  rdoc_options: []
45
73
 
46
74
  require_paths:
47
- - ext
75
+ - ext
48
76
  required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
49
78
  requirements:
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- segments:
53
- - 0
54
- version: "0"
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
55
85
  required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
56
87
  requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- segments:
60
- - 0
61
- version: "0"
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
62
94
  requirements: []
63
95
 
64
96
  rubyforge_project:
65
- rubygems_version: 1.3.6
97
+ rubygems_version: 1.5.2
66
98
  signing_key:
67
99
  specification_version: 3
68
100
  summary: C extensions for Ruby BSON.