Esempio n. 1
0
    def _one_statement(self, method_name, stream, bypass_types):
        """
        Route to the correct optimized function for one statement queries

        :param method_name: the name of the method
        :type method_name: string
        :param stream: the stream of tokens
        :type stream: iterable of tokens
        :param bypass_types: set if parsing should bypass types
        :type bypass_types: boolean
        """
        sql = Tokens2Unicode(stream)

        if self._paramstyle:
            sql = self._paramstyle(sql)

        # Insert statement (return last row id)
        if IsType('INSERT')(stream):
            return self._one_statement_INSERT(method_name, sql, bypass_types)

        ## Update statement (return affected row count)
        #if IsType('UPDATE')(stream):
        #    return self._one_statement_UPDATE(method_name, sql, bypass_types)

        # One-value function (a row of a cell)
        if getlimit(stream) == 1:
            columns = getcolumns(stream)

            # Value function (one row, one field)
            if len(columns) == 1 and columns[0] != '*':
                return self._one_statement_value(method_name, sql, bypass_types)

            # Register function (one row, several fields)
            return self._one_statement_register(method_name, sql, bypass_types)

        # Table function (several rows)
        return self._one_statement_table(method_name, sql, bypass_types)
Esempio n. 2
0
 def test_getcolumns3(self):
     columns = getcolumns(tokenize(self.sql3))
     self.assertEqual(columns, ['st_dev', 'st_uid', 'st_gid', 'st_mode',
                                'st_ino', 'st_nlink', 'st_ctime',
                                'st_atime', 'st_mtime', 'st_size', 'size'])
Esempio n. 3
0
 def test_getcolumns2(self):
     columns = getcolumns(tokenize(self.sql2))
     self.assertEqual(columns, ['child_entry', 'inode', 'creation'])
Esempio n. 4
0
 def test_getcolumns1(self):
     columns = getcolumns(tokenize(self.sql))
     self.assertEqual(columns, [])