/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.    
 */
#ifndef RESULT_SET_H
#define RESULT_SET_H

#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#include <string>

#include "apache/das/rdb/StatementPtr.h"
#include "apache/das/RefCountingObject.h"
#include "apache/das/rdb/ResultSetMetaData.h"
#include "apache/das/rdb/DASInvalidSQLTypeException.h"

namespace apache {
	namespace das {
		namespace rdb {

class Statement;
class ResultSetMetaData;
class ResultSet;

typedef RefCountingObject<ResultSet> ResultSetObject;

class ResultSet : public ResultSetObject {

	private:
		ResultSetMetaData* metaData;
		StatementPtr stmt;

		std::string getSQLString(unsigned int columnIndex) const;
		std::wstring getSQLWString(unsigned int columnIndex) const;

	public:
		ResultSet(StatementPtr aStmt);
		virtual ~ResultSet(void);

		const ResultSetMetaData& getResultSetMetaData(void) const;
		StatementPtr getStatement(void) const;
		
		SQLCHAR getSQLChar(unsigned int columnIndex) const;
		SQLCHAR getSQLChar(std::string tableName, std::string columnName) const;

		std::string getSQLVarchar(unsigned int columnIndex) const;
		std::string getSQLVarchar(std::string tableName, std::string columnName) const;

		SQLWCHAR getSQLWChar(unsigned int columnIndex) const;
		SQLWCHAR getSQLWChar(std::string tableName, std::string columnName) const;

		std::wstring getSQLWVarchar(unsigned int columnIndex) const;
		std::wstring getSQLWVarchar(std::string tableName, std::string columnName) const;

		SQLREAL getSQLReal(unsigned int columnIndex) const;
		SQLREAL getSQLReal(std::string tableName, std::string columnName) const;

		SQLFLOAT getSQLFloat(unsigned int columnIndex) const;
		SQLFLOAT getSQLFloat(std::string tableName, std::string columnName) const;

		SQLDOUBLE getSQLDouble(unsigned int columnIndex) const;
		SQLDOUBLE getSQLDouble(std::string tableName, std::string columnName) const;

		std::string getSQLDecimal(unsigned int columnIndex) const;
		std::string getSQLDecimal(std::string tableName, std::string columnName) const;

		SQLINTEGER getSQLInteger(unsigned int columnIndex) const;
		SQLINTEGER getSQLInteger(std::string tableName, std::string columnName) const;

		SQLSMALLINT getSQLSmallInt(unsigned int columnIndex) const;
		SQLSMALLINT getSQLSmallInt(std::string tableName, std::string columnName) const;

		bool isNull(unsigned int columnIndex) const;
		bool isNull(std::string tableName, std::string columnName) const;

		unsigned int getRowCount(void) const;

		bool next(void);
		
};

		};
	};
};

#endif //RESULT_SET_H
