bson_ext 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,55 +1,100 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: bson_ext
3
- version: !ruby/object:Gem::Version
4
- version: 1.5.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 1
5
5
  prerelease:
6
+ segments:
7
+ - 1
8
+ - 5
9
+ - 1
10
+ version: 1.5.1
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Mike Dirolf
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-11-28 00:00:00.000000000Z
17
+
18
+ date: 2011-11-29 00:00:00 Z
13
19
  dependencies: []
14
- description: C extensions to accelerate the Ruby BSON serialization. For more information
15
- about BSON, see http://bsonspec.org. For information about MongoDB, see http://www.mongodb.org.
20
+
21
+ description: C extensions to accelerate the Ruby BSON serialization. For more information about BSON, see http://bsonspec.org. For information about MongoDB, see http://www.mongodb.org.
16
22
  email: mongodb-dev@googlegroups.com
17
23
  executables: []
18
- extensions:
24
+
25
+ extensions:
19
26
  - ext/cbson/extconf.rb
20
27
  extra_rdoc_files: []
21
- files:
28
+
29
+ files:
22
30
  - Rakefile
23
31
  - bson_ext.gemspec
24
32
  - ext/cbson/extconf.rb
25
33
  - ext/cbson/bson_buffer.c
26
34
  - ext/cbson/cbson.c
27
35
  - ext/cbson/encoding_helpers.c
36
+ - ext/cmongo/c-driver/src/bson.c
37
+ - ext/cmongo/c-driver/src/gridfs.c
38
+ - ext/cmongo/c-driver/src/md5.c
39
+ - ext/cmongo/c-driver/src/mongo.c
40
+ - ext/cmongo/c-driver/src/numbers.c
41
+ - ext/cmongo/c-driver/test/all_types.c
42
+ - ext/cmongo/c-driver/test/auth.c
43
+ - ext/cmongo/c-driver/test/benchmark.c
44
+ - ext/cmongo/c-driver/test/count_delete.c
45
+ - ext/cmongo/c-driver/test/endian_swap.c
46
+ - ext/cmongo/c-driver/test/errors.c
47
+ - ext/cmongo/c-driver/test/examples.c
48
+ - ext/cmongo/c-driver/test/gridfs.c
49
+ - ext/cmongo/c-driver/test/json.c
50
+ - ext/cmongo/c-driver/test/pair.c
51
+ - ext/cmongo/c-driver/test/replica_set.c
52
+ - ext/cmongo/c-driver/test/resize.c
53
+ - ext/cmongo/c-driver/test/simple.c
54
+ - ext/cmongo/c-driver/test/sizes.c
55
+ - ext/cmongo/c-driver/test/update.c
28
56
  - ext/cbson/bson_buffer.h
29
57
  - ext/cbson/encoding_helpers.h
30
58
  - ext/cbson/version.h
59
+ - ext/cmongo/c-driver/src/bson.h
60
+ - ext/cmongo/c-driver/src/gridfs.h
61
+ - ext/cmongo/c-driver/src/md5.h
62
+ - ext/cmongo/c-driver/src/mongo.h
63
+ - ext/cmongo/c-driver/src/mongo_except.h
64
+ - ext/cmongo/c-driver/src/platform_hacks.h
65
+ - ext/cmongo/c-driver/test/test.h
31
66
  homepage: http://www.mongodb.org
32
67
  licenses: []
68
+
33
69
  post_install_message:
34
70
  rdoc_options: []
35
- require_paths:
71
+
72
+ require_paths:
36
73
  - ext
37
- required_ruby_version: !ruby/object:Gem::Requirement
74
+ required_ruby_version: !ruby/object:Gem::Requirement
38
75
  none: false
39
- requirements:
40
- - - ! '>='
41
- - !ruby/object:Gem::Version
42
- version: '0'
43
- required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
84
  none: false
45
- requirements:
46
- - - ! '>='
47
- - !ruby/object:Gem::Version
48
- version: '0'
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
49
92
  requirements: []
93
+
50
94
  rubyforge_project:
51
- rubygems_version: 1.8.10
95
+ rubygems_version: 1.8.11
52
96
  signing_key:
53
97
  specification_version: 3
54
98
  summary: C extensions for Ruby BSON.
55
99
  test_files: []
100
+