@@ -846,7 +846,7 @@ CRUD_TEST_BEGIN(find)
846
846
847
847
Expr criteria (criteria_str);
848
848
849
- Reply find (sess.coll_find (coll, &criteria, NULL ));
849
+ Reply find (sess.coll_find (coll, NULL , &criteria, NULL ));
850
850
Cursor c (find);
851
851
852
852
set_meta_data (c);
@@ -869,7 +869,7 @@ CRUD_TEST_BEGIN(find)
869
869
870
870
Expr criteria (criteria_str);
871
871
872
- Reply find (sess.coll_find (coll, &criteria, NULL ));
872
+ Reply find (sess.coll_find (coll, NULL , &criteria, NULL ));
873
873
Cursor c (find);
874
874
875
875
set_meta_data (c);
@@ -1054,7 +1054,7 @@ CRUD_TEST_BEGIN(update)
1054
1054
1055
1055
// Show data after update.
1056
1056
1057
- Reply find (sess.coll_find (coll, &which));
1057
+ Reply find (sess.coll_find (coll, NULL , &which));
1058
1058
Cursor c (find);
1059
1059
set_meta_data (c);
1060
1060
c.get_rows (*this );
@@ -1088,7 +1088,7 @@ CRUD_TEST_BEGIN(update)
1088
1088
1089
1089
// Show data after update.
1090
1090
1091
- Reply find (sess.coll_find (coll, &which));
1091
+ Reply find (sess.coll_find (coll, NULL , &which));
1092
1092
Cursor c (find);
1093
1093
set_meta_data (c);
1094
1094
c.get_rows (*this );
@@ -1173,7 +1173,7 @@ CRUD_TEST_BEGIN(parameters)
1173
1173
param_values;
1174
1174
1175
1175
{
1176
- Reply find (sess.coll_find (coll, &expr, NULL , NULL , NULL , NULL , NULL , ¶m_values));
1176
+ Reply find (sess.coll_find (coll, NULL , &expr, NULL , NULL , NULL , NULL , NULL , ¶m_values));
1177
1177
Cursor c (find);
1178
1178
1179
1179
set_meta_data (c);
@@ -1205,7 +1205,7 @@ CRUD_TEST_BEGIN(parameters)
1205
1205
}
1206
1206
1207
1207
{
1208
- Reply find (sess.coll_find (coll, &expr, NULL , NULL , NULL , NULL , NULL , ¶m_values));
1208
+ Reply find (sess.coll_find (coll, NULL , &expr, NULL , NULL , NULL , NULL , NULL , ¶m_values));
1209
1209
Cursor c (find);
1210
1210
1211
1211
set_meta_data (c);
@@ -1226,7 +1226,7 @@ CRUD_TEST_BEGIN(parameters)
1226
1226
}
1227
1227
1228
1228
{
1229
- Reply find (sess.coll_find (coll, &expr, NULL , NULL , NULL , NULL , NULL , ¶m_values));
1229
+ Reply find (sess.coll_find (coll, NULL , &expr, NULL , NULL , NULL , NULL , NULL , ¶m_values));
1230
1230
Cursor c (find);
1231
1231
1232
1232
set_meta_data (c);
@@ -1287,6 +1287,7 @@ CRUD_TEST_BEGIN(projections)
1287
1287
1288
1288
Reply find (
1289
1289
sess.coll_find (coll,
1290
+ NULL , // view spec
1290
1291
NULL , // where
1291
1292
&projection,
1292
1293
NULL , // sort
@@ -1360,7 +1361,7 @@ CRUD_TEST_BEGIN(projections)
1360
1361
}
1361
1362
projection;
1362
1363
1363
- Reply find (sess.table_select (coll, &criteria, &projection));
1364
+ Reply find (sess.table_select (coll, NULL , &criteria, &projection));
1364
1365
Cursor c (find);
1365
1366
1366
1367
set_meta_data (c);
@@ -1447,7 +1448,7 @@ CRUD_TEST_BEGIN(insert)
1447
1448
1448
1449
{
1449
1450
TExpr cond (" id IS NULL AND extra IS NULL" );
1450
- Reply check (sess.table_select (tbl, &cond));
1451
+ Reply check (sess.table_select (tbl, NULL , &cond));
1451
1452
Cursor c (check);
1452
1453
set_meta_data (c);
1453
1454
c.get_rows (*this );
@@ -1540,6 +1541,7 @@ CRUD_TEST_BEGIN(group_by)
1540
1541
1541
1542
Reply find (
1542
1543
sess.coll_find (coll,
1544
+ NULL , // view spec
1543
1545
NULL , // where
1544
1546
&projection,
1545
1547
NULL , // sort
@@ -1604,6 +1606,7 @@ CRUD_TEST_BEGIN(group_by)
1604
1606
1605
1607
Reply find (
1606
1608
sess.table_select (tbl,
1609
+ NULL , // view spec
1607
1610
NULL , // where
1608
1611
&projection,
1609
1612
NULL , // sort
@@ -1626,3 +1629,201 @@ CRUD_TEST_BEGIN(group_by)
1626
1629
cout <<" Done!" <<endl;
1627
1630
}
1628
1631
CRUD_TEST_END
1632
+
1633
+
1634
+ CRUD_TEST_BEGIN (views)
1635
+ {
1636
+ Session sess (this );
1637
+
1638
+ if (!sess.is_valid ())
1639
+ FAIL () << " Invalid Session created" ;
1640
+
1641
+ cout << " Session established" << endl;
1642
+
1643
+ struct View_spec : cdk::View_spec
1644
+ {
1645
+ Table_ref v;
1646
+ String_list *columns;
1647
+ cdk::View_spec::Options *opts;
1648
+
1649
+ View_spec ()
1650
+ : v(" view" , " test" )
1651
+ , columns(NULL )
1652
+ , opts(NULL )
1653
+ {}
1654
+
1655
+ void process (Processor &prc) const
1656
+ {
1657
+ prc.name (v);
1658
+ if (columns)
1659
+ columns->process_if (prc.columns ());
1660
+ if (opts)
1661
+ opts->process_if (prc.options ());
1662
+ }
1663
+ }
1664
+ view;
1665
+
1666
+ cout << " Creating collection view..." << endl;
1667
+
1668
+ // Drop the view first, if it already exists.
1669
+
1670
+ {
1671
+ Reply drop (sess.view_drop (view.v ));
1672
+ drop.wait ();
1673
+ if (0 < drop.entry_count ())
1674
+ drop.get_error ().rethrow ();
1675
+ }
1676
+
1677
+ {
1678
+ struct : public View_spec ::Options
1679
+ {
1680
+ void process (Processor &prc) const
1681
+ {
1682
+ prc.security (View_security::DEFINER);
1683
+ prc.check (View_check::LOCAL);
1684
+ }
1685
+ }
1686
+ view_opts;
1687
+
1688
+ view.opts = &view_opts;
1689
+
1690
+ struct : public Expression ::Document
1691
+ {
1692
+ void process (Processor &prc) const
1693
+ {
1694
+ Path name_path (" name" );
1695
+ Path age_path (" age" );
1696
+ Expr double_age (" 2*age" );
1697
+ Safe_prc<Processor> sprc (prc);
1698
+
1699
+ prc.doc_begin ();
1700
+
1701
+ sprc->key_val (" name_proj" )->scalar ()->ref (name_path);
1702
+ double_age.process_if (sprc->key_val (" age_proj" ));
1703
+ sprc->key_val (" extra.orig_age" )->scalar ()->ref (age_path);
1704
+ sprc->key_val (" extra.val" )->scalar ()->val ()->str (" bar" );
1705
+
1706
+ prc.doc_end ();
1707
+ }
1708
+ }
1709
+ projection;
1710
+
1711
+ Expr cond (" name LIKE 'ba%'" );
1712
+
1713
+ Reply create (sess.coll_find (coll, &view, &cond, &projection));
1714
+ create.wait ();
1715
+ if (0 < create.entry_count ())
1716
+ create.get_error ().rethrow ();
1717
+ }
1718
+
1719
+ cout << " View created, querying it..." << endl;
1720
+
1721
+ {
1722
+ Reply select (sess.coll_find (view.v ));
1723
+ select.wait ();
1724
+
1725
+ cout << " Got reply..." << endl;
1726
+
1727
+ Cursor c (select);
1728
+
1729
+ set_meta_data (c);
1730
+ c.get_rows (*this );
1731
+ c.wait ();
1732
+ }
1733
+
1734
+
1735
+ cout << " Creating table view..." << endl;
1736
+
1737
+ // Drop the view first.
1738
+
1739
+ {
1740
+ Reply drop (sess.view_drop (view.v , false ));
1741
+ drop.wait ();
1742
+ if (0 < drop.entry_count ())
1743
+ drop.get_error ().rethrow ();
1744
+ }
1745
+
1746
+ {
1747
+ struct : public View_spec ::Options
1748
+ {
1749
+ void process (Processor &prc) const
1750
+ {
1751
+ prc.security (View_security::INVOKER);
1752
+ prc.algorithm (View_algorithm::UNDEFINED);
1753
+ }
1754
+ }
1755
+ view_opts;
1756
+
1757
+ view.opts = &view_opts;
1758
+
1759
+ struct : public Projection
1760
+ {
1761
+ void process (Processor &prc) const
1762
+ {
1763
+ Processor::Element_prc *ep;
1764
+
1765
+ prc.list_begin ();
1766
+
1767
+ if ((ep = prc.list_el ()))
1768
+ {
1769
+ TExpr proj (L" name" );
1770
+ proj.process_if (ep->expr ());
1771
+ // no alias
1772
+ }
1773
+
1774
+ if ((ep = prc.list_el ()))
1775
+ {
1776
+ TExpr proj (L" 2 * age" );
1777
+ proj.process_if (ep->expr ());
1778
+ ep->alias (L" double age" );
1779
+ }
1780
+
1781
+ prc.list_end ();
1782
+ }
1783
+ }
1784
+ projection;
1785
+
1786
+ struct : public cdk ::String_list
1787
+ {
1788
+ void process (Processor &prc) const
1789
+ {
1790
+ prc.list_begin ();
1791
+ safe_prc (prc)->list_el ()->val (" view_name" );
1792
+ safe_prc (prc)->list_el ()->val (" view_age" );
1793
+ prc.list_end ();
1794
+ }
1795
+ }
1796
+ columns;
1797
+
1798
+ view.columns = &columns;
1799
+
1800
+ TExpr cond (" name LIKE 'ba%'" );
1801
+
1802
+ Reply create (sess.table_select (tbl, &view, &cond, &projection));
1803
+ create.wait ();
1804
+ if (0 < create.entry_count ())
1805
+ create.get_error ().rethrow ();
1806
+ }
1807
+
1808
+ cout << " View created, querying it..." << endl;
1809
+
1810
+ {
1811
+ Reply select (sess.table_select (view.v ));
1812
+ select.wait ();
1813
+
1814
+ cout << " Got reply..." << endl;
1815
+
1816
+ Cursor c (select);
1817
+
1818
+ EXPECT_EQ (L" view_name" , c.col_info (0 ).name ());
1819
+ EXPECT_EQ (L" view_age" , c.col_info (1 ).name ());
1820
+
1821
+ set_meta_data (c);
1822
+ c.get_rows (*this );
1823
+ c.wait ();
1824
+ }
1825
+
1826
+
1827
+ cout <<" Done!" <<endl;
1828
+ }
1829
+ CRUD_TEST_END
0 commit comments