Skip to content

Commit c3747b5

Browse files
committed
Include BitSpec from @Narigo
1 parent 3408711 commit c3747b5

File tree

3 files changed

+168
-0
lines changed

3 files changed

+168
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2013 Maurício Linhares
3+
*
4+
* Maurício Linhares licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package com.github.mauricio.async.db.mysql
18+
19+
import org.specs2.mutable.Specification
20+
21+
class BitSpec extends Specification with ConnectionHelper {
22+
23+
"when processing bit columns" should {
24+
25+
"result in binary data" in {
26+
27+
withConnection {
28+
connection =>
29+
val create = """CREATE TEMPORARY TABLE binary_test
30+
(
31+
id INT NOT NULL AUTO_INCREMENT,
32+
some_bit BIT(1) NOT NULL,
33+
PRIMARY KEY (id)
34+
)"""
35+
36+
executeQuery(connection, create)
37+
executePreparedStatement(connection,
38+
"INSERT INTO binary_test (some_bit) VALUES (B'0'),(B'1')")
39+
40+
val rows = executePreparedStatement(connection, "select * from binary_test").rows.get
41+
42+
val bit0 = rows(0)("some_bit")
43+
val bit1 = rows(1)("some_bit")
44+
45+
bit0 === Array(0)
46+
bit1 === Array(1)
47+
}
48+
49+
}
50+
51+
"result in binary data in BIT(2) column" in {
52+
53+
withConnection {
54+
connection =>
55+
val create = """CREATE TEMPORARY TABLE binary_test
56+
(
57+
id INT NOT NULL AUTO_INCREMENT,
58+
some_bit BIT(2) NOT NULL,
59+
CONSTRAINT bigserial_column_pkey PRIMARY KEY (id)
60+
)"""
61+
62+
executeQuery(connection, create)
63+
executePreparedStatement(connection,
64+
"INSERT INTO binary_test (some_bit) VALUES (B'00'),(B'01'),(B'10'),(B'11')")
65+
66+
val rows = executePreparedStatement(connection, "select * from binary_test").rows.get
67+
68+
val bit0 = rows(0)("some_bit")
69+
val bit1 = rows(1)("some_bit")
70+
val bit2 = rows(2)("some_bit")
71+
val bit3 = rows(3)("some_bit")
72+
73+
bit0 === Array(0)
74+
bit1 === Array(1)
75+
bit2 === Array(2)
76+
bit3 === Array(3)
77+
}
78+
79+
}
80+
81+
}
82+
83+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2013 Maurício Linhares
3+
*
4+
* Maurício Linhares licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package com.github.mauricio.async.db.postgresql
18+
19+
import org.specs2.mutable.Specification
20+
21+
class BitSpec extends Specification with DatabaseTestHelper {
22+
23+
"when processing bit columns" should {
24+
25+
"result in binary data" in {
26+
27+
withHandler {
28+
handler =>
29+
val create = """CREATE TEMP TABLE binary_test
30+
(
31+
id bigserial NOT NULL,
32+
some_bit BYTEA NOT NULL,
33+
CONSTRAINT bigserial_column_pkey PRIMARY KEY (id)
34+
)"""
35+
36+
executeDdl(handler, create)
37+
executePreparedStatement(handler,
38+
"INSERT INTO binary_test (some_bit) VALUES (E'\\\\000'),(E'\\\\001')")
39+
40+
val rows = executePreparedStatement(handler, "select * from binary_test").rows.get
41+
42+
val bit0 = rows(0)("some_bit")
43+
val bit1 = rows(1)("some_bit")
44+
45+
bit0 === Array(0)
46+
bit1 === Array(1)
47+
}
48+
49+
}
50+
51+
"result in binary data in BIT(2) column" in {
52+
53+
withHandler {
54+
handler =>
55+
val create = """CREATE TEMP TABLE binary_test
56+
(
57+
id bigserial NOT NULL,
58+
some_bit BYTEA NOT NULL,
59+
CONSTRAINT bigserial_column_pkey PRIMARY KEY (id)
60+
)"""
61+
62+
executeDdl(handler, create)
63+
executePreparedStatement(handler,
64+
"INSERT INTO binary_test (some_bit) VALUES (E'\\\\000'),(E'\\\\001'),(E'\\\\002'),(E'\\\\003')")
65+
66+
val rows = executePreparedStatement(handler, "select * from binary_test").rows.get
67+
68+
val bit0 = rows(0)("some_bit")
69+
val bit1 = rows(1)("some_bit")
70+
val bit2 = rows(2)("some_bit")
71+
val bit3 = rows(3)("some_bit")
72+
73+
bit0 === Array(0)
74+
bit1 === Array(1)
75+
bit2 === Array(2)
76+
bit3 === Array(3)
77+
}
78+
79+
}
80+
81+
}
82+
83+
}

project/Build.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ object Configuration {
5454
val specs2Version = "2.5"
5555

5656
val specs2Dependency = "org.specs2" %% "specs2-core" % specs2Version % "test"
57+
val specs2JunitDependency = "org.specs2" %% "specs2-junit" % specs2Version % "test"
5758
val logbackDependency = "ch.qos.logback" % "logback-classic" % "1.1.6" % "test"
5859

5960
val commonDependencies = Seq(
@@ -63,6 +64,7 @@ object Configuration {
6364
"io.netty" % "netty-all" % "4.0.34.Final",
6465
"org.javassist" % "javassist" % "3.20.0-GA",
6566
specs2Dependency,
67+
specs2JunitDependency,
6668
logbackDependency
6769
)
6870

0 commit comments

Comments
 (0)