LCOV - code coverage report
Current view: top level - sql/backends/monet5 - sql_orderidx.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 50 0.0 %
Date: 2021-10-13 02:24:04 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : /* (c) M.L. Kersten
      10             :  * The order index interface routines are defined here.
      11             : */
      12             : #include "monetdb_config.h"
      13             : #include "mal_backend.h"
      14             : #include "sql_scenario.h"
      15             : #include "sql_result.h"
      16             : #include "sql_gencode.h"
      17             : #include "sql_optimizer.h"
      18             : #include "sql_env.h"
      19             : #include "sql_mvc.h"
      20             : #include "sql_orderidx.h"
      21             : #include "orderidx.h"
      22             : #include "sql_scenario.h"
      23             : 
      24             : str
      25           0 : sql_createorderindex(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      26             : {
      27           0 :         mvc *m = NULL;
      28           0 :         str msg = getSQLContext(cntxt, mb, &m, NULL);
      29             :         str sch,tbl,col;
      30             :         sql_schema *s;
      31             :         sql_table *t;
      32             :         sql_column *c;
      33             :         BAT *b;
      34             : 
      35           0 :         if (msg != MAL_SUCCEED || (msg = checkSQLContext(cntxt)) != NULL)
      36           0 :                 return msg;
      37             : 
      38           0 :         sch = *getArgReference_str(stk, pci, 1);
      39           0 :         tbl = *getArgReference_str(stk, pci, 2);
      40           0 :         col = *getArgReference_str(stk, pci, 3);
      41             : 
      42           0 :         if (!(s = mvc_bind_schema(m, sch)))
      43           0 :                 throw(SQL, "sql.createorderindex", SQLSTATE(3FOOO) "Unknown schema %s", sch);
      44           0 :         if (!mvc_schema_privs(m, s))
      45           0 :                 throw(SQL, "sql.createorderindex", SQLSTATE(42000) "Access denied for %s to schema '%s'", get_string_global_var(m, "current_user"), s->base.name);
      46           0 :         if (!(t = mvc_bind_table(m, s, tbl)))
      47           0 :                 throw(SQL, "sql.createorderindex", SQLSTATE(42S02) "Unknown table %s.%s", sch, tbl);
      48           0 :         if (!isTable(t))
      49           0 :                 throw(SQL, "sql.createorderindex", SQLSTATE(42000) "%s '%s' is not persistent", TABLE_TYPE_DESCRIPTION(t->type, t->properties), t->base.name);
      50           0 :         if (!(c = mvc_bind_column(m, t, col)))
      51           0 :                 throw(SQL, "sql.createorderindex", SQLSTATE(38000) "Unknown column %s.%s.%s", sch, tbl, col);
      52           0 :         sqlstore *store = m->session->tr->store;
      53           0 :         b = store->storage_api.bind_col(m->session->tr, c, 0);
      54           0 :         if (b == 0)
      55           0 :                 throw(SQL,"sql.createorderindex", SQLSTATE(HY005) "Column can not be accessed");
      56             :         /* create the ordered index on the column */
      57           0 :         msg = OIDXcreateImplementation(cntxt, newBatType(b->ttype), b, -1);
      58           0 :         BBPunfix(b->batCacheid);
      59           0 :         return msg;
      60             : }
      61             : 
      62             : str
      63           0 : sql_droporderindex(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      64             : {
      65           0 :         mvc *m = NULL;
      66           0 :         str msg = getSQLContext(cntxt, mb, &m, NULL);
      67             :         str sch,tbl,col;
      68             :         sql_schema *s;
      69             :         sql_table *t;
      70             :         sql_column *c;
      71             :         BAT *b;
      72             : 
      73           0 :         if (msg != MAL_SUCCEED || (msg = checkSQLContext(cntxt)) != NULL)
      74           0 :                 return msg;
      75             : 
      76           0 :         sch = *getArgReference_str(stk, pci, 1);
      77           0 :         tbl = *getArgReference_str(stk, pci, 2);
      78           0 :         col = *getArgReference_str(stk, pci, 3);
      79             : 
      80           0 :         if (!(s = mvc_bind_schema(m, sch)))
      81           0 :                 throw(SQL, "sql.droporderindex", SQLSTATE(3FOOO) "Unknown schema %s", sch);
      82           0 :         if (!mvc_schema_privs(m, s))
      83           0 :                 throw(SQL, "sql.droporderindex", SQLSTATE(42000) "Access denied for %s to schema '%s'", get_string_global_var(m, "current_user"), s->base.name);
      84           0 :         if (!(t = mvc_bind_table(m, s, tbl)))
      85           0 :                 throw(SQL, "sql.droporderindex", SQLSTATE(42S02) "Unknown table %s.%s", sch, tbl);
      86           0 :         if (!isTable(t))
      87           0 :                 throw(SQL, "sql.droporderindex", SQLSTATE(42000) "%s '%s' is not persistent", TABLE_TYPE_DESCRIPTION(t->type, t->properties), t->base.name);
      88           0 :         if (!(c = mvc_bind_column(m, t, col)))
      89           0 :                 throw(SQL, "sql.droporderindex", SQLSTATE(38000) "Unknown column %s.%s.%s", sch, tbl, col);
      90           0 :         sqlstore *store = m->session->tr->store;
      91           0 :         b = store->storage_api.bind_col(m->session->tr, c, 0);
      92           0 :         if (b == 0)
      93           0 :                 throw(SQL,"sql.droporderindex", SQLSTATE(38000) "Column can not be accessed");
      94           0 :         msg = OIDXdropImplementation(cntxt, b);
      95           0 :         BBPunfix(b->batCacheid);
      96           0 :         return msg;
      97             : }

Generated by: LCOV version 1.14