@@ -28,35 +28,39 @@ public MySQL connect() throws SQLException {
2828 }
2929 }
3030
31- @ Test public void testCreateTable ( ) {
31+ public boolean createTables ( SQL con ) {
3232 try {
33- MySQL mySQL = connect ();
34-
3533 // Table
36- ITable table = mySQL .table ("users" );
37-
38- if (mySQL .table ("test" ).exists ()) {
39- System .out .println ("Table test already exists, deleting." );
40-
41- table .drop ().execute ();
42- }
34+ ITable table = con .table ("users" );
4335
4436 // Create table
45- Create create = table .create ();
37+ Create create = table .create (). ifNotExists () ;
4638
4739 // Table columns
4840 create .id ();
4941 create .string ("first_name" );
5042 create .string ("last_name" );
51- create .string ("test" );
43+ create .string ("test" ). nullable () ;
5244
5345 Boolean result = create .execute ();
5446
5547 // Print query string and result.
5648 System .out .println (create );
5749 System .out .println (result );
5850
59- assertFalse (result );
51+ return result ;
52+ } catch (SQLException e ) {
53+ e .printStackTrace ();
54+
55+ return true ;
56+ }
57+ }
58+
59+ @ Test public void testCreateTable () {
60+ try {
61+ MySQL mySQL = connect ();
62+
63+ assertFalse (createTables (mySQL ));
6064 } catch (SQLException e ) {
6165 e .printStackTrace ();
6266 }
@@ -66,6 +70,8 @@ public MySQL connect() throws SQLException {
6670 try {
6771 MySQL mySQL = connect ();
6872
73+ createTables (mySQL );
74+
6975 // Alter columns
7076 Alter alter = mySQL .table ("users" ).alter ();
7177
@@ -99,6 +105,8 @@ public MySQL connect() throws SQLException {
99105 try {
100106 MySQL mySQL = connect ();
101107
108+ createTables (mySQL );
109+
102110 // Insert
103111 Insert query = mySQL .table ("users" ).insert (new HashMap <String , Object >(){{
104112 put ("first_name" , "Denzel" );
@@ -120,6 +128,8 @@ public MySQL connect() throws SQLException {
120128 try {
121129 MySQL mySQL = connect ();
122130
131+ createTables (mySQL );
132+
123133 // Update
124134 Update query = mySQL .table ("users" ).update (new HashMap <String , Object >(){{
125135 put ("token" , "Advanced" );
@@ -140,6 +150,8 @@ public MySQL connect() throws SQLException {
140150 try {
141151 MySQL mySQL = connect ();
142152
153+ createTables (mySQL );
154+
143155 // Select
144156 Select query = mySQL .table ("users" ).select ();
145157 Map <String , Object > fetch = query .fetch ();
@@ -158,14 +170,21 @@ public MySQL connect() throws SQLException {
158170 try {
159171 MySQL mySQL = connect ();
160172
173+ createTables (mySQL );
174+
175+ mySQL .table ("users" ).insert (new HashMap <String , Object >(){{
176+ put ("first_name" , "Denzel" );
177+ put ("last_name" , "Code" );
178+ }}).execute ();
179+
161180 // Create information table
162181 ITable table = mySQL .table ("information" );
163182
164183 // Delete table if exists.
165184 if (mySQL .table ("information" ).exists ()) table .drop ().execute ();
166185
167186 // Create table
168- Create create = table .create ();
187+ Create create = table .create (). ifNotExists () ;
169188
170189 // Table columns
171190 create .id ();
@@ -208,6 +227,13 @@ public MySQL connect() throws SQLException {
208227 try {
209228 MySQL mySQL = connect ();
210229
230+ createTables (mySQL );
231+
232+ mySQL .table ("users" ).insert (new HashMap <String , Object >(){{
233+ put ("first_name" , "Denzel" );
234+ put ("last_name" , "Code" );
235+ }}).execute ();
236+
211237 // Delete
212238 Delete query = mySQL .table ("users" ).delete ().where ("first_name = ?" , "Denzel" );
213239 int execute = query .execute ();
@@ -216,7 +242,7 @@ public MySQL connect() throws SQLException {
216242 System .out .println (query );
217243 System .out .println (execute );
218244
219- assertEquals ( 1 , execute );
245+ assertNotEquals ( 0 , execute );
220246 } catch (SQLException e ) {
221247 e .printStackTrace ();
222248 }
@@ -226,6 +252,8 @@ public MySQL connect() throws SQLException {
226252 try {
227253 MySQL mySQL = connect ();
228254
255+ createTables (mySQL );
256+
229257 // Truncate table
230258 Truncate query = mySQL .table ("users" ).truncate ();
231259 Boolean execute = query .execute ();
@@ -244,6 +272,8 @@ public MySQL connect() throws SQLException {
244272 try {
245273 MySQL mySQL = connect ();
246274
275+ createTables (mySQL );
276+
247277 // Drop table
248278 com .code .advancedsql .query .Drop query = mySQL .table ("users" ).drop ();
249279 Boolean execute = query .execute ();
0 commit comments