SOL9 2.0 Class: ADOFields

 SOL9 C++ Class Library  SOL9 Samples  SOL9 Tutorial  SOL9 FAQ  SOL9 ClassTree 

Source code

/*
 * ADOFields.h 
 * Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL9
// 2009/05/12

#pragma once

#include <sol/sql/ADOCollection.h>
#include <sol/sql/ADOField.h>


namespace SOL {

class ADOFields :public ADOCollection {

public:
    ADOFields()
    {
    }

public:
    ~ADOFields()
    {
    }

public:
    HRESULT createInstance()
    {
        return ADOObject::createInstance(__uuidof(ADODB::Fields));
    }

public:
    void set(ADODB::FieldsPtr pFs)
    {
        setObject((IDispatchPtr)pFs);
    }

public:
    ADODB::FieldsPtr getFieldsPtr()
    {
        return (ADODB::FieldsPtr)getObject();
    }

public:
    // 2009/05/12
    bool getItem(
            __in long index, 
            __out ADOField& field)
    {
        return getItem(_variant_t(index), field);
    }
    
public:
    // 2009/05/12
    bool getItem(
            __in const _variant_t& index, 
            __out ADOField& field)
    {
        bool rc = false;
        ADODB::FieldPtr pField = getItem(index);
        if (pField) {
            field.set(pField);
            rc = true;
        } else {
            throw Exception(E_FAIL, "%s: %s", "E_FAIL", __FUNCTION__);

        }
        return rc;
    }
    
public:

    ADODB::FieldPtr getItem(
            __in const _variant_t& index)
    {
        return getFieldsPtr()->GetItem (index);
    }

public:
    HRESULT remove(
        __in const _variant_t & index)
    {
        HRESULT hr = getFieldsPtr()->Delete(index);
        if (FAILED(hr)) {
            throw Exception(hr, "%s", __FUNCTION__);
        }
        return hr;

    }

public:
    HRESULT append(
        __in _bstr_t name,
        __in ADODB::DataTypeEnum type,
        __in ADODB::ADO_LONGPTR definedSize,
        __in ADODB::FieldAttributeEnum attrib,
        __in_opt const _variant_t& fieldValue = vtMissing)
    {
        HRESULT hr = getFieldsPtr()->Append(
                name,
                   type,
                   definedSize,
                   attrib,
                fieldValue);
        if (FAILED(hr)) {
            throw Exception(hr, "%s", __FUNCTION__);
        }
        return hr;

    }

public:
    HRESULT update()
    {
        HRESULT hr = getFieldsPtr()->Update();
        if (FAILED(hr)) {
            throw Exception(hr, "%s", __FUNCTION__);
        }
        return hr;

    }

public:
    HRESULT resync(ADODB::ResyncEnum resyncValues)
    {
        HRESULT hr = getFieldsPtr()->Resync(resyncValues);
        if (FAILED(hr)) {
            throw Exception(hr, "%s", __FUNCTION__);
        }
        return hr;

    }

public:
    HRESULT cancelUpdate()
    {
        HRESULT hr = getFieldsPtr()->CancelUpdate();
        if (FAILED(hr)) {
            throw Exception(hr, "%s", __FUNCTION__);
        }
        return hr;

    }

public:
    long getCount()
    {
        return getFieldsPtr()->GetCount();
    }

public:
    HRESULT refresh()
    {
        HRESULT hr = getFieldsPtr()->Refresh();
        if (FAILED(hr)) {
            throw Exception(hr, "%s", __FUNCTION__);
        };
        return hr;
    }

public:
    IUnknownPtr newEnum() 
    {
        return     getFieldsPtr()->_NewEnum();
    }

public:
    // 2009/05/26
    long getNameIndex(__in _bstr_t& name)
    {
        long index = -1L;    //Not found
        long count = getCount();
        const wchar_t* wname = (const wchar_t*)name;

        for (long i = 0L; i<count; i++) {
            ADOField field;
            getItem(_variant_t(i), field);
            _bstr_t n = field.getName();
            const wchar_t* wn = (const wchar_t*)n;
            if (wname && wn && wcsicmp(wname, wn) == 0) {
                index = i;    
                break;
            }
        }
        if (index == -1L) {
            throw Exception(E_FAIL, "Not found index for fieldName=\"%S\": %s",
                    (const wchar_t*)name, __FUNCTION__);
        }
        return index;    
    }

public:
    // 2009/05/23
    void dump()
    {
        long count = getCount();
        printf("Fields:\n");
        for (long i = 0L; i<count; i++) {
            ADOField field;
            getItem(_variant_t(i), field);
            field.dump();
        }
    }

};

}

Last modified: 1 Feb 2012

Copyright (c) 2009-2012 Antillia.com ALL RIGHTS RESERVED.