src/ResultSet.h
branchv_0
changeset 36 91cb012d779a
child 43 7f396cdb9628
equal deleted inserted replaced
35:cd9db43db120 36:91cb012d779a
       
     1 /**
       
     2  * Relational pipes
       
     3  * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
       
     4  *
       
     5  * This program is free software: you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation, version 3.
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
       
    16  */
       
    17 #pragma once
       
    18 
       
    19 #include <codecvt>
       
    20 #include <locale>
       
    21 #include <vector>
       
    22 
       
    23 #include <relpipe/writer/typedefs.h>
       
    24 #include <relpipe/writer/TypeId.h>
       
    25 
       
    26 namespace relpipe {
       
    27 namespace tr {
       
    28 namespace sql {
       
    29 
       
    30 class ResultSet {
       
    31 public:
       
    32 
       
    33 	class MetaData {
       
    34 	public:
       
    35 
       
    36 		class ColumnDescriptor {
       
    37 		public:
       
    38 			relpipe::writer::string_t name;
       
    39 			relpipe::writer::TypeId type = relpipe::writer::TypeId::STRING;
       
    40 		};
       
    41 
       
    42 	private:
       
    43 		unsigned short columnCount;
       
    44 		std::vector<ColumnDescriptor> columnDescriptors;
       
    45 
       
    46 	public:
       
    47 		MetaData(unsigned short columnCount, std::vector<ColumnDescriptor> columnDescriptors);
       
    48 		virtual ~MetaData();
       
    49 		unsigned short getColumnCount();
       
    50 		ColumnDescriptor describeColumn(unsigned short columnNumber);
       
    51 	};
       
    52 private:
       
    53 	void* statement;
       
    54 	std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings
       
    55 
       
    56 public:
       
    57 	ResultSet(void* statement);
       
    58 	virtual ~ResultSet();
       
    59 	MetaData* getMetaData();
       
    60 	bool next();
       
    61 	relpipe::writer::boolean_t getBoolean(unsigned short columnNumber, bool* isNull = nullptr);
       
    62 	relpipe::writer::integer_t getInteger(unsigned short columnNumber, bool* isNull = nullptr);
       
    63 	relpipe::writer::string_t getString(unsigned short columnNumber, bool* isNull = nullptr);
       
    64 };
       
    65 
       
    66 }
       
    67 }
       
    68 }