25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

581 satır
25 KiB

  1. #include <cpphibernate/driver/mariadb.h>
  2. #include "test_helper.h"
  3. #include "test_schema.h"
  4. #include "mariadb_mock.h"
  5. using namespace ::testing;
  6. using namespace ::cpphibernate;
  7. TEST(CppHibernateTests, create_test1)
  8. {
  9. StrictMock<mariadb_mock> mock;
  10. expect_query(mock, "START TRANSACTION");
  11. expect_query(mock, "SELECT Uuid()", result_used({
  12. { "3d12697a-abb9-11e8-98d0-529269fb1459" }
  13. }));
  14. expect_query(mock, "INSERT INTO "
  15. "`tbl_test1` "
  16. "SET "
  17. "`tbl_test1_id`=UuidToBin('X3d12697a-abb9-11e8-98d0-529269fb1459X'), "
  18. "`str_data`='Xstr_data of class `test1` object `t1`X', "
  19. "`str64_data`='Xstr64_data of class `test1` object `t1`X', "
  20. "`u32_nullable`=null, "
  21. "`u32_ptr_u`='X456X', "
  22. "`u32_ptr_s`='X789X'",
  23. result_affected_rows(1));
  24. expect_query(mock, "COMMIT");
  25. EXPECT_CALL(
  26. mock,
  27. mysql_real_escape_string(reinterpret_cast<MYSQL*>(0x1111), _, _, _))
  28. .Times(AnyNumber())
  29. .WillRepeatedly(WithArgs<1, 2, 3>(EscapeString()));
  30. EXPECT_CALL(
  31. mock,
  32. mysql_close(
  33. reinterpret_cast<MYSQL*>(0x1111)));
  34. test1 t1;
  35. t1.str_data = "str_data of class `test1` object `t1`";
  36. t1.str64_data = "str64_data of class `test1` object `t1`";
  37. t1.u32_ptr_u = std::make_unique<uint32_t>(456);
  38. t1.u32_ptr_s = std::make_shared<uint32_t>(789);
  39. ::cppmariadb::connection connection(reinterpret_cast<MYSQL*>(0x1111));
  40. auto context = make_context<mariadb_driver>(test_schema, connection);
  41. context.create(t1);
  42. }
  43. #if 0
  44. TEST(CppHibernateTests, create_test2)
  45. {
  46. StrictMock<mariadb_mock> mock;
  47. expect_query(mock, "START TRANSACTION");
  48. expect_query(mock, "SELECT Uuid()", result_used({
  49. { "3d1270dc-abb9-11e8-98d0-529269fb1459" }
  50. }));
  51. expect_query(mock, "INSERT INTO "
  52. "`tbl_test2` "
  53. "SET "
  54. "`tbl_test2_id`=UuidToBin('X3d1270dc-abb9-11e8-98d0-529269fb1459X'), "
  55. "`u8_data`='X1X', "
  56. "`i8_data`='X2X', "
  57. "`u16_data`='X3X', "
  58. "`i16_data`='X4X'",
  59. result_affected_rows(1));
  60. expect_query(mock, "COMMIT");
  61. EXPECT_CALL(
  62. mock,
  63. mysql_real_escape_string(reinterpret_cast<MYSQL*>(0x1111), _, _, _))
  64. .Times(AnyNumber())
  65. .WillRepeatedly(WithArgs<1, 2, 3>(EscapeString()));
  66. EXPECT_CALL(
  67. mock,
  68. mysql_close(
  69. reinterpret_cast<MYSQL*>(0x1111)));
  70. test2 t2;
  71. t2.u8_data = 1;
  72. t2.i8_data = 2;
  73. t2.u16_data = 3;
  74. t2.i16_data = 4;
  75. ::cppmariadb::connection connection(reinterpret_cast<MYSQL*>(0x1111));
  76. auto context = make_context<driver::mariadb>(test_schema, connection);
  77. context.create(t2);
  78. }
  79. TEST(CppHibernateTests, create_test3)
  80. {
  81. StrictMock<mariadb_mock> mock;
  82. expect_query(mock, "START TRANSACTION");
  83. expect_query(mock, "SELECT Uuid()", result_used({
  84. { "3d12737a-abb9-11e8-98d0-529269fb1459" }
  85. }));
  86. expect_query(mock, "INSERT INTO "
  87. "`tbl_test3` "
  88. "SET "
  89. "`tbl_test3_id`=UuidToBin('X3d12737a-abb9-11e8-98d0-529269fb1459X'), "
  90. "`tbl_derived3_id_test3_list`=UuidToBin(null), "
  91. "`tbl_derived3_index_test3_list`='X0X', "
  92. "`tbl_derived3_id_test3_vector`=UuidToBin(null), "
  93. "`tbl_derived3_index_test3_vector`='X0X', "
  94. "`u32_data`='X5X', "
  95. "`i32_data`='X6X', "
  96. "`u64_data`='X7X', "
  97. "`i64_data`='X8X'",
  98. result_affected_rows(1));
  99. expect_query(mock, "COMMIT");
  100. EXPECT_CALL(
  101. mock,
  102. mysql_real_escape_string(reinterpret_cast<MYSQL*>(0x1111), _, _, _))
  103. .Times(AnyNumber())
  104. .WillRepeatedly(WithArgs<1, 2, 3>(EscapeString()));
  105. EXPECT_CALL(
  106. mock,
  107. mysql_close(
  108. reinterpret_cast<MYSQL*>(0x1111)));
  109. test3 t3;
  110. t3.u32_data = 5;
  111. t3.i32_data = 6;
  112. t3.u64_data = 7;
  113. t3.i64_data = 8;
  114. ::cppmariadb::connection connection(reinterpret_cast<MYSQL*>(0x1111));
  115. auto context = make_context<driver::mariadb>(test_schema, connection);
  116. context.create(t3);
  117. }
  118. TEST(CppHibernateTests, create_derived1)
  119. {
  120. StrictMock<mariadb_mock> mock;
  121. expect_query(mock, "START TRANSACTION");
  122. expect_query(mock, "SELECT Uuid()", result_used({
  123. { "3d12758c-abb9-11e8-98d0-529269fb1459" }
  124. }));
  125. expect_query(mock, "SELECT Uuid()", result_used({
  126. { "3d12778a-abb9-11e8-98d0-529269fb1459" }
  127. }));
  128. expect_query(mock, "INSERT INTO "
  129. "`tbl_base` "
  130. "SET "
  131. "`tbl_base_id`=UuidToBin('X3d12778a-abb9-11e8-98d0-529269fb1459X'), "
  132. "`name`='Xderived1X', "
  133. "`__type`='X11X'",
  134. result_affected_rows(1));
  135. expect_query(mock, "SELECT Uuid()", result_used({
  136. { "3d127988-abb9-11e8-98d0-529269fb1459" }
  137. }));
  138. expect_query(mock, "INSERT INTO "
  139. "`tbl_test1` "
  140. "SET "
  141. "`tbl_test1_id`=UuidToBin('X3d127988-abb9-11e8-98d0-529269fb1459X'), "
  142. "`str_data`='Xstr_data of class `test1` object `d1.test1_data`X', "
  143. "`str64_data`='Xstr64_data of class `test1` object `d1.test1_data`X', "
  144. "`u32_nullable`='X32X', "
  145. "`u32_ptr_u`=null, "
  146. "`u32_ptr_s`='X789X'",
  147. result_affected_rows(1));
  148. expect_query(mock, "INSERT INTO "
  149. "`tbl_derived1` "
  150. "SET "
  151. "`tbl_derived1_id`=UuidToBin('X3d12758c-abb9-11e8-98d0-529269fb1459X'), "
  152. "`tbl_base_id`=UuidToBin('X3d12778a-abb9-11e8-98d0-529269fb1459X'), "
  153. "`tbl_test1_id_test1_data`=UuidToBin('X3d127988-abb9-11e8-98d0-529269fb1459X'), "
  154. "`enum_data`='Xtest2X'",
  155. result_affected_rows(1));
  156. expect_query(mock, "COMMIT");
  157. EXPECT_CALL(
  158. mock,
  159. mysql_real_escape_string(reinterpret_cast<MYSQL*>(0x1111), _, _, _))
  160. .Times(AnyNumber())
  161. .WillRepeatedly(WithArgs<1, 2, 3>(EscapeString()));
  162. EXPECT_CALL(
  163. mock,
  164. mysql_close(
  165. reinterpret_cast<MYSQL*>(0x1111)));
  166. derived1 d1;
  167. d1.name = "derived1";
  168. d1.enum_data = test_enum::test2;
  169. d1.test1_data.str_data = "str_data of class `test1` object `d1.test1_data`";
  170. d1.test1_data.str64_data = "str64_data of class `test1` object `d1.test1_data`";
  171. d1.test1_data.u32_nullable = 32;
  172. d1.test1_data.u32_ptr_s = std::make_shared<uint32_t>(789);
  173. ::cppmariadb::connection connection(reinterpret_cast<MYSQL*>(0x1111));
  174. auto context = make_context<driver::mariadb>(test_schema, connection);
  175. context.create(static_cast<base&>(d1));
  176. }
  177. TEST(CppHibernateTests, create_derived2)
  178. {
  179. StrictMock<mariadb_mock> mock;
  180. expect_query(mock, "START TRANSACTION");
  181. expect_query(mock, "SELECT Uuid()", result_used({
  182. { "3d127bcc-abb9-11e8-98d0-529269fb1459" }
  183. }));
  184. expect_query(mock, "SELECT Uuid()", result_used({
  185. { "3d127db6-abb9-11e8-98d0-529269fb1459" }
  186. }));
  187. expect_query(mock, "INSERT INTO "
  188. "`tbl_base` "
  189. "SET "
  190. "`tbl_base_id`=UuidToBin('X3d127db6-abb9-11e8-98d0-529269fb1459X'), "
  191. "`name`='Xderived2X', "
  192. "`__type`='X12X'",
  193. result_affected_rows(1));
  194. expect_query(mock, "SELECT Uuid()", result_used({
  195. { "3d1283a6-abb9-11e8-98d0-529269fb1459" }
  196. }));
  197. expect_query(mock, "INSERT INTO "
  198. "`tbl_test2` "
  199. "SET "
  200. "`tbl_test2_id`=UuidToBin('X3d1283a6-abb9-11e8-98d0-529269fb1459X'), "
  201. "`u8_data`='X10X', "
  202. "`i8_data`='X11X', "
  203. "`u16_data`='X12X', "
  204. "`i16_data`='X13X'",
  205. result_affected_rows(1));
  206. expect_query(mock, "SELECT Uuid()", result_used({
  207. { "3d128522-abb9-11e8-98d0-529269fb1459" }
  208. }));
  209. expect_query(mock, "INSERT INTO "
  210. "`tbl_test2` "
  211. "SET "
  212. "`tbl_test2_id`=UuidToBin('X3d128522-abb9-11e8-98d0-529269fb1459X'), "
  213. "`u8_data`='X20X', "
  214. "`i8_data`='X21X', "
  215. "`u16_data`='X22X', "
  216. "`i16_data`='X23X'",
  217. result_affected_rows(1));
  218. expect_query(mock, "INSERT INTO "
  219. "`tbl_derived2` "
  220. "SET "
  221. "`tbl_derived2_id`=UuidToBin('X3d127bcc-abb9-11e8-98d0-529269fb1459X'), "
  222. "`tbl_base_id`=UuidToBin('X3d127db6-abb9-11e8-98d0-529269fb1459X'), "
  223. "`tbl_test2_id_test2_nullable`=UuidToBin('X3d1283a6-abb9-11e8-98d0-529269fb1459X'), "
  224. "`tbl_test2_id_test2_ptr_u`=UuidToBin('X3d128522-abb9-11e8-98d0-529269fb1459X'), "
  225. "`tbl_test2_id_test2_ptr_s`=UuidToBin(null)",
  226. result_affected_rows(1));
  227. expect_query(mock, "COMMIT");
  228. EXPECT_CALL(
  229. mock,
  230. mysql_real_escape_string(reinterpret_cast<MYSQL*>(0x1111), _, _, _))
  231. .Times(AnyNumber())
  232. .WillRepeatedly(WithArgs<1, 2, 3>(EscapeString()));
  233. EXPECT_CALL(
  234. mock,
  235. mysql_close(
  236. reinterpret_cast<MYSQL*>(0x1111)));
  237. derived2 d2;
  238. d2.name = "derived2";
  239. d2.test2_nullable = test2 { };
  240. d2.test2_nullable->u8_data = 10;
  241. d2.test2_nullable->i8_data = 11;
  242. d2.test2_nullable->u16_data = 12;
  243. d2.test2_nullable->i16_data = 13;
  244. d2.test2_ptr_u = std::make_unique<test2>();
  245. d2.test2_ptr_u->u8_data = 20;
  246. d2.test2_ptr_u->i8_data = 21;
  247. d2.test2_ptr_u->u16_data = 22;
  248. d2.test2_ptr_u->i16_data = 23;
  249. ::cppmariadb::connection connection(reinterpret_cast<MYSQL*>(0x1111));
  250. auto context = make_context<driver::mariadb>(test_schema, connection);
  251. context.create(static_cast<base&>(d2));
  252. }
  253. TEST(CppHibernateTests, create_derived3)
  254. {
  255. StrictMock<mariadb_mock> mock;
  256. expect_query(mock, "START TRANSACTION");
  257. expect_query(mock, "SELECT Uuid()", result_used({
  258. { "3d12866c-abb9-11e8-98d0-529269fb1459" }
  259. }));
  260. expect_query(mock, "SELECT Uuid()", result_used({
  261. { "3d1287a2-abb9-11e8-98d0-529269fb1459" }
  262. }));
  263. expect_query(mock, "SELECT Uuid()", result_used({
  264. { "3d1288ce-abb9-11e8-98d0-529269fb1459" }
  265. }));
  266. expect_query(mock, "INSERT INTO "
  267. "`tbl_base` "
  268. "SET "
  269. "`tbl_base_id`=UuidToBin('X3d1288ce-abb9-11e8-98d0-529269fb1459X'), "
  270. "`name`='Xderived3X', "
  271. "`__type`='X13X'",
  272. result_affected_rows(1));
  273. expect_query(mock, "INSERT INTO "
  274. "`tbl_derived2` "
  275. "SET "
  276. "`tbl_derived2_id`=UuidToBin('X3d1287a2-abb9-11e8-98d0-529269fb1459X'), "
  277. "`tbl_base_id`=UuidToBin('X3d1288ce-abb9-11e8-98d0-529269fb1459X'), "
  278. "`tbl_test2_id_test2_nullable`=UuidToBin(null), "
  279. "`tbl_test2_id_test2_ptr_u`=UuidToBin(null), "
  280. "`tbl_test2_id_test2_ptr_s`=UuidToBin(null)",
  281. result_affected_rows(1));
  282. expect_query(mock, "INSERT INTO "
  283. "`tbl_derived3` "
  284. "SET "
  285. "`tbl_derived3_id`=UuidToBin('X3d12866c-abb9-11e8-98d0-529269fb1459X'), "
  286. "`tbl_derived2_id`=UuidToBin('X3d1287a2-abb9-11e8-98d0-529269fb1459X')",
  287. result_affected_rows(1));
  288. expect_query(mock, "SELECT Uuid()", result_used({
  289. { "3d1289f0-abb9-11e8-98d0-529269fb1459" }
  290. }));
  291. expect_query(mock, "INSERT INTO "
  292. "`tbl_test3` "
  293. "SET "
  294. "`tbl_test3_id`=UuidToBin('X3d1289f0-abb9-11e8-98d0-529269fb1459X'), "
  295. "`tbl_derived3_id_test3_list`=UuidToBin('X3d12866c-abb9-11e8-98d0-529269fb1459X'), "
  296. "`tbl_derived3_index_test3_list`='X0X', "
  297. "`tbl_derived3_id_test3_vector`=UuidToBin(null), "
  298. "`tbl_derived3_index_test3_vector`='X0X', "
  299. "`u32_data`='X100X', "
  300. "`i32_data`='X101X', "
  301. "`u64_data`='X102X', "
  302. "`i64_data`='X103X'",
  303. result_affected_rows(1));
  304. expect_query(mock, "SELECT Uuid()", result_used({
  305. { "3d128b26-abb9-11e8-98d0-529269fb1459" }
  306. }));
  307. expect_query(mock, "INSERT INTO "
  308. "`tbl_test3` "
  309. "SET "
  310. "`tbl_test3_id`=UuidToBin('X3d128b26-abb9-11e8-98d0-529269fb1459X'), "
  311. "`tbl_derived3_id_test3_list`=UuidToBin('X3d12866c-abb9-11e8-98d0-529269fb1459X'), "
  312. "`tbl_derived3_index_test3_list`='X1X', "
  313. "`tbl_derived3_id_test3_vector`=UuidToBin(null), "
  314. "`tbl_derived3_index_test3_vector`='X0X', "
  315. "`u32_data`='X110X', "
  316. "`i32_data`='X111X', "
  317. "`u64_data`='X112X', "
  318. "`i64_data`='X113X'",
  319. result_affected_rows(1));
  320. expect_query(mock, "SELECT Uuid()", result_used({
  321. { "3d128eb4-abb9-11e8-98d0-529269fb1459" }
  322. }));
  323. expect_query(mock, "INSERT INTO "
  324. "`tbl_test3` "
  325. "SET "
  326. "`tbl_test3_id`=UuidToBin('X3d128eb4-abb9-11e8-98d0-529269fb1459X'), "
  327. "`tbl_derived3_id_test3_list`=UuidToBin(null), "
  328. "`tbl_derived3_index_test3_list`='X0X', "
  329. "`tbl_derived3_id_test3_vector`=UuidToBin('X3d12866c-abb9-11e8-98d0-529269fb1459X'), "
  330. "`tbl_derived3_index_test3_vector`='X0X', "
  331. "`u32_data`='X200X', "
  332. "`i32_data`='X201X', "
  333. "`u64_data`='X202X', "
  334. "`i64_data`='X203X'",
  335. result_affected_rows(1));
  336. expect_query(mock, "SELECT Uuid()", result_used({
  337. { "3d128ffe-abb9-11e8-98d0-529269fb1459" }
  338. }));
  339. expect_query(mock, "INSERT INTO "
  340. "`tbl_test3` "
  341. "SET "
  342. "`tbl_test3_id`=UuidToBin('X3d128ffe-abb9-11e8-98d0-529269fb1459X'), "
  343. "`tbl_derived3_id_test3_list`=UuidToBin(null), "
  344. "`tbl_derived3_index_test3_list`='X0X', "
  345. "`tbl_derived3_id_test3_vector`=UuidToBin('X3d12866c-abb9-11e8-98d0-529269fb1459X'), "
  346. "`tbl_derived3_index_test3_vector`='X1X', "
  347. "`u32_data`='X210X', "
  348. "`i32_data`='X211X', "
  349. "`u64_data`='X212X', "
  350. "`i64_data`='X213X'",
  351. result_affected_rows(1));
  352. expect_query(mock, "SELECT Uuid()", result_used({
  353. { "3d129134-abb9-11e8-98d0-529269fb1459" }
  354. }));
  355. expect_query(mock, "INSERT INTO "
  356. "`tbl_test3` "
  357. "SET "
  358. "`tbl_test3_id`=UuidToBin('X3d129134-abb9-11e8-98d0-529269fb1459X'), "
  359. "`tbl_derived3_id_test3_list`=UuidToBin(null), "
  360. "`tbl_derived3_index_test3_list`='X0X', "
  361. "`tbl_derived3_id_test3_vector`=UuidToBin('X3d12866c-abb9-11e8-98d0-529269fb1459X'), "
  362. "`tbl_derived3_index_test3_vector`='X2X', "
  363. "`u32_data`='X220X', "
  364. "`i32_data`='X221X', "
  365. "`u64_data`='X222X', "
  366. "`i64_data`='X223X'",
  367. result_affected_rows(1));
  368. expect_query(mock, "COMMIT");
  369. EXPECT_CALL(
  370. mock,
  371. mysql_real_escape_string(reinterpret_cast<MYSQL*>(0x1111), _, _, _))
  372. .Times(AnyNumber())
  373. .WillRepeatedly(WithArgs<1, 2, 3>(EscapeString()));
  374. EXPECT_CALL(
  375. mock,
  376. mysql_close(
  377. reinterpret_cast<MYSQL*>(0x1111)));
  378. derived3 d3;
  379. d3.name = "derived3";
  380. d3.test3_list.emplace_back();
  381. d3.test3_list.back().u32_data = 100;
  382. d3.test3_list.back().i32_data = 101;
  383. d3.test3_list.back().u64_data = 102;
  384. d3.test3_list.back().i64_data = 103;
  385. d3.test3_list.emplace_back();
  386. d3.test3_list.back().u32_data = 110;
  387. d3.test3_list.back().i32_data = 111;
  388. d3.test3_list.back().u64_data = 112;
  389. d3.test3_list.back().i64_data = 113;
  390. d3.test3_vector.emplace_back();
  391. d3.test3_vector.back().u32_data = 200;
  392. d3.test3_vector.back().i32_data = 201;
  393. d3.test3_vector.back().u64_data = 202;
  394. d3.test3_vector.back().i64_data = 203;
  395. d3.test3_vector.emplace_back();
  396. d3.test3_vector.back().u32_data = 210;
  397. d3.test3_vector.back().i32_data = 211;
  398. d3.test3_vector.back().u64_data = 212;
  399. d3.test3_vector.back().i64_data = 213;
  400. d3.test3_vector.emplace_back();
  401. d3.test3_vector.back().u32_data = 220;
  402. d3.test3_vector.back().i32_data = 221;
  403. d3.test3_vector.back().u64_data = 222;
  404. d3.test3_vector.back().i64_data = 223;
  405. ::cppmariadb::connection connection(reinterpret_cast<MYSQL*>(0x1111));
  406. auto context = make_context<driver::mariadb>(test_schema, connection);
  407. context.create(static_cast<derived2&>(d3));
  408. }
  409. TEST(CppHibernateTests, create_dummy_owner)
  410. {
  411. StrictMock<mariadb_mock> mock;
  412. expect_query(mock, "START TRANSACTION");
  413. expect_query(mock, "SELECT Uuid()", result_used({
  414. { "00000000-0000-0000-0000-000000000001" }
  415. }));
  416. expect_query(mock, "INSERT INTO "
  417. "`tbl_dummy_owner` "
  418. "SET "
  419. "`tbl_dummy_owner_id`=UuidToBin('X00000000-0000-0000-0000-000000000001X')",
  420. result_affected_rows(1));
  421. expect_query(mock, "SELECT Uuid()", result_used({
  422. { "00000000-0000-0000-0001-000000000001" }
  423. }));
  424. expect_query(mock, "INSERT INTO "
  425. "`tbl_dummy_id` "
  426. "SET "
  427. "`tbl_dummy_id_id`=UuidToBin('X00000000-0000-0000-0001-000000000001X'), "
  428. "`tbl_dummy_owner_id_dummies`=UuidToBin('X00000000-0000-0000-0000-000000000001X'), "
  429. "`tbl_dummy_owner_index_dummies`='X0X', "
  430. "`data`='X123X'",
  431. result_affected_rows(1));
  432. expect_query(mock, "SELECT Uuid()", result_used({
  433. { "00000000-0000-0000-0001-000000000002" }
  434. }));
  435. expect_query(mock, "INSERT INTO "
  436. "`tbl_dummy_id` "
  437. "SET "
  438. "`tbl_dummy_id_id`=UuidToBin('X00000000-0000-0000-0001-000000000002X'), "
  439. "`tbl_dummy_owner_id_dummies`=UuidToBin('X00000000-0000-0000-0000-000000000001X'), "
  440. "`tbl_dummy_owner_index_dummies`='X1X', "
  441. "`data`='X456X'",
  442. result_affected_rows(1));
  443. expect_query(mock, "SELECT Uuid()", result_used({
  444. { "00000000-0000-0000-0001-000000000003" }
  445. }));
  446. expect_query(mock, "INSERT INTO "
  447. "`tbl_dummy_id` "
  448. "SET "
  449. "`tbl_dummy_id_id`=UuidToBin('X00000000-0000-0000-0001-000000000003X'), "
  450. "`tbl_dummy_owner_id_dummies`=UuidToBin('X00000000-0000-0000-0000-000000000001X'), "
  451. "`tbl_dummy_owner_index_dummies`='X2X', "
  452. "`data`='X789X'",
  453. result_affected_rows(1));
  454. expect_query(mock, "COMMIT");
  455. EXPECT_CALL(
  456. mock,
  457. mysql_real_escape_string(reinterpret_cast<MYSQL*>(0x1111), _, _, _))
  458. .Times(AnyNumber())
  459. .WillRepeatedly(WithArgs<1, 2, 3>(EscapeString()));
  460. EXPECT_CALL(
  461. mock,
  462. mysql_close(
  463. reinterpret_cast<MYSQL*>(0x1111)));
  464. dummy_owner d;
  465. d.dummies.emplace_back(123);
  466. d.dummies.emplace_back(456);
  467. d.dummies.emplace_back(789);
  468. ::cppmariadb::connection connection(reinterpret_cast<MYSQL*>(0x1111));
  469. auto context = make_context<driver::mariadb>(test_schema, connection);
  470. context.create(d);
  471. }
  472. TEST(CppHibernateTests, create_double_usage)
  473. {
  474. StrictMock<mariadb_mock> mock;
  475. expect_query(mock, "START TRANSACTION");
  476. expect_query(mock, "INSERT INTO `tbl_double_usage`",
  477. result_id(1));
  478. expect_query(mock, "INSERT INTO "
  479. "`tbl_double_usage_item` "
  480. "SET "
  481. "`tbl_double_usage_id_single_item`='X1X', "
  482. "`tbl_double_usage_id_multiple_items`=null, "
  483. "`tbl_double_usage_index_multiple_items`='X0X', "
  484. "`data`='X123X'",
  485. result_id(1001));
  486. expect_query(mock, "INSERT INTO "
  487. "`tbl_double_usage_item` "
  488. "SET "
  489. "`tbl_double_usage_id_single_item`=null, "
  490. "`tbl_double_usage_id_multiple_items`='X1X', "
  491. "`tbl_double_usage_index_multiple_items`='X0X', "
  492. "`data`='X456X'",
  493. result_id(1002));
  494. expect_query(mock, "INSERT INTO "
  495. "`tbl_double_usage_item` "
  496. "SET "
  497. "`tbl_double_usage_id_single_item`=null, "
  498. "`tbl_double_usage_id_multiple_items`='X1X', "
  499. "`tbl_double_usage_index_multiple_items`='X1X', "
  500. "`data`='X789X'",
  501. result_id(1003));
  502. expect_query(mock, "COMMIT");
  503. EXPECT_CALL(
  504. mock,
  505. mysql_real_escape_string(reinterpret_cast<MYSQL*>(0x1111), _, _, _))
  506. .Times(AnyNumber())
  507. .WillRepeatedly(WithArgs<1, 2, 3>(EscapeString()));
  508. EXPECT_CALL(
  509. mock,
  510. mysql_close(
  511. reinterpret_cast<MYSQL*>(0x1111)));
  512. double_usage d;
  513. d.single_item.reset(new double_usage_item(123));
  514. d.multiple_items.emplace_back(456);
  515. d.multiple_items.emplace_back(789);
  516. ::cppmariadb::connection connection(reinterpret_cast<MYSQL*>(0x1111));
  517. auto context = make_context<driver::mariadb>(test_schema, connection);
  518. context.create(d);
  519. EXPECT_EQ(d.id, 1);
  520. EXPECT_EQ(d.single_item->id, 1001);
  521. EXPECT_EQ(d.multiple_items[0].id, 1002);
  522. EXPECT_EQ(d.multiple_items[1].id, 1003);
  523. }
  524. #endif