bson_ext 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -4
- data/ext/cbson/{buffer.c → bson_buffer.c} +30 -14
- data/ext/cbson/{buffer.h → bson_buffer.h} +16 -12
- data/ext/cbson/cbson.c +61 -56
- data/ext/cbson/version.h +1 -1
- data/ext/cmongo/c-driver/src/bson.c +699 -0
- data/ext/cmongo/c-driver/src/bson.h +229 -0
- data/ext/cmongo/c-driver/src/gridfs.c +799 -0
- data/ext/cmongo/c-driver/src/gridfs.h +278 -0
- data/ext/cmongo/c-driver/src/md5.c +381 -0
- data/ext/cmongo/c-driver/src/md5.h +91 -0
- data/ext/cmongo/c-driver/src/mongo.c +1020 -0
- data/ext/cmongo/c-driver/src/mongo.h +260 -0
- data/ext/cmongo/c-driver/src/mongo_except.h +143 -0
- data/ext/cmongo/c-driver/src/numbers.c +127 -0
- data/ext/cmongo/c-driver/src/platform_hacks.h +93 -0
- data/ext/cmongo/c-driver/test/all_types.c +223 -0
- data/ext/cmongo/c-driver/test/auth.c +28 -0
- data/ext/cmongo/c-driver/test/benchmark.c +434 -0
- data/ext/cmongo/c-driver/test/count_delete.c +64 -0
- data/ext/cmongo/c-driver/test/endian_swap.c +31 -0
- data/ext/cmongo/c-driver/test/errors.c +71 -0
- data/ext/cmongo/c-driver/test/examples.c +75 -0
- data/ext/cmongo/c-driver/test/gridfs.c +217 -0
- data/ext/cmongo/c-driver/test/json.c +169 -0
- data/ext/cmongo/c-driver/test/pair.c +41 -0
- data/ext/cmongo/c-driver/test/replica_set.c +81 -0
- data/ext/cmongo/c-driver/test/resize.c +35 -0
- data/ext/cmongo/c-driver/test/simple.c +110 -0
- data/ext/cmongo/c-driver/test/sizes.c +22 -0
- data/ext/cmongo/c-driver/test/test.h +19 -0
- data/ext/cmongo/c-driver/test/update.c +107 -0
- metadata +61 -29
@@ -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
|
-
|
4
|
+
hash: 7
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
version: 1.
|
7
|
+
- 1
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 1.4.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
|
-
|
13
|
+
- Mike Dirolf
|
13
14
|
autorequire:
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-
|
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
|
-
|
27
|
+
- ext/cbson/extconf.rb
|
27
28
|
extra_rdoc_files: []
|
28
29
|
|
29
30
|
files:
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
75
|
+
- ext
|
48
76
|
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
49
78
|
requirements:
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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.
|
97
|
+
rubygems_version: 1.5.2
|
66
98
|
signing_key:
|
67
99
|
specification_version: 3
|
68
100
|
summary: C extensions for Ruby BSON.
|