Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not be reset NULL in a column with gsSetRowFieldByXXX() #3

Closed
knonomura opened this issue Jan 23, 2019 · 1 comment
Closed

Can not be reset NULL in a column with gsSetRowFieldByXXX() #3

knonomura opened this issue Jan 23, 2019 · 1 comment

Comments

@knonomura
Copy link
Member

When GSRow object is reused, it can not be reset NULL in a column with gsSetRowFieldByXXX().

This is a sample code.
#include "gridstore.h"
#include <stdio.h>

int sample1(const char *addr, const char *port, const char *clusterName, const char *user, const char *passwd) {
    GSResult ret = EXIT_FAILURE;
    GSGridStore *store;
    const GSPropertyEntry props[] = {
            { "notificationAddress", addr },
            { "notificationPort", port },
            { "clusterName", clusterName },
            { "user", user },
            { "password", passwd } };
    const size_t propCount = sizeof(props) / sizeof(*props);
    ret = gsGetGridStore(gsGetDefaultFactory(), props, propCount, &store);
    ret != GS_RESULT_OK ? printf("gsGetGridStore failed %d\n",ret) : 0;

    GSContainer *col;
    GSRow *colRow;
    GSBool bExists;
    GSColumnInfo colInfoList[3] = { {"long", GS_TYPE_LONG},
                                    {"float", GS_TYPE_FLOAT},
                                    {"byte", GS_TYPE_BYTE}};
    GSContainerInfo colInfo = {"col",
                                GS_CONTAINER_COLLECTION,
                                3,
                                colInfoList,
                                GS_TRUE,
                                GS_TRUE,
                                NULL, 0, NULL, NULL,0, NULL};
    ret = gsDropContainer(store, "col");
    ret != GS_RESULT_OK ? printf("gsDropContainer failed %d\n",ret) : 0;
    ret = gsPutContainerGeneral(store, "col", &colInfo, GS_FALSE, &col);
    ret != GS_RESULT_OK ? printf("gsPutContainerGeneral failed %d\n",ret) : 0;
    ret = gsSetAutoCommit(col, false);
    ret != GS_RESULT_OK ? printf("gsSetAutoCommit failed %d\n",ret) : 0;

    ret = gsCreateRowByContainer(col, &colRow);
    ret != GS_RESULT_OK ? printf("gsCreateRowByContainer failed %d\n",ret) : 0;

    ret = gsSetRowFieldByLong(colRow, 0, 111);
    ret != GS_RESULT_OK ? printf("gsSetRowFieldByLong failed %d\n",ret) : 0;
    ret = gsSetRowFieldByFloat(colRow, 1, 1.1);
    ret != GS_RESULT_OK ? printf("gsSetRowFieldByFloat failed %d\n",ret) : 0;
    ret = gsSetRowFieldNull(colRow, 2);// NULL
    ret != GS_RESULT_OK ? printf("gsSetRowFieldNull failed %d\n",ret) : 0;
    ret = gsPutRow(col, NULL, colRow, &bExists);
    ret != GS_RESULT_OK ? printf("gsPutRow failed %d\n",ret) : 0;
    ret = gsCommit(col);
    ret != GS_RESULT_OK ? printf("gsCommit failed %d\n",ret) : 0;

    ret = gsSetRowFieldByLong(colRow, 0, 222);
    ret != GS_RESULT_OK ? printf("gsSetRowFieldByLong failed %d\n",ret) : 0;
    ret = gsSetRowFieldNull(colRow, 1);// NULL
    ret != GS_RESULT_OK ? printf("gsSetRowFieldNull failed %d\n",ret) : 0;
    ret = gsSetRowFieldByByte(colRow, 2, 2);
    ret != GS_RESULT_OK ? printf("gsSetRowFieldByByte failed %d\n",ret) : 0;
    ret = gsPutRow(col, NULL, colRow, &bExists);
    ret != GS_RESULT_OK ? printf("gsPutRow failed %d\n",ret) : 0;
    ret = gsCommit(col);
    ret != GS_RESULT_OK ? printf("gsCommit failed %d\n",ret) : 0;

    int64_t l = 111;
    GSBool nullValue;
    void *key = &l;
    ret = gsGetRow(col, key, colRow, &bExists);
    ret != GS_RESULT_OK ? printf("gsGetRow failed %d\n",ret) : 0;
    ret = gsGetRowFieldNull(colRow, 1, &nullValue);
    ret != GS_RESULT_OK ? printf("gsGetRowFieldNull failed %d\n",ret) : 0;
    if (nullValue) {
        printf("rowKey = %d, field 1 is null [NG]\n", l);
    }
    ret = gsGetRowFieldNull(colRow, 2, &nullValue);
    ret != GS_RESULT_OK ? printf("gsGetRowFieldNull failed %d\n",ret) : 0;
    if (nullValue) {
        printf("rowKey = %d, field 2 is null [OK]\n", l);
    }
    l = 222;
    ret = gsGetRow(col, key, colRow, &bExists);
    ret != GS_RESULT_OK ? printf("gsGetRow failed %d\n",ret) : 0;
    ret = gsGetRowFieldNull(colRow, 1, &nullValue);
    ret != GS_RESULT_OK ? printf("gsGetRowFieldNull failed %d\n",ret) : 0;
    if (nullValue) {
        printf("rowKey = %d, field 1 is null [OK]\n", l);
    }
    ret = gsGetRowFieldNull(colRow, 2, &nullValue);
    ret != GS_RESULT_OK ? printf("gsGetRowFieldNull failed %d\n",ret) : 0;
    if (nullValue) {
        printf("rowKey = %d, field 2 is null [NG]\n", l);
    }

    gsCloseRow(&colRow);
    gsCloseContainer(&col, GS_FALSE);
    gsCloseGridStore(&store, GS_FALSE);
    return 0;
}

int main(int argc,char *argv[]){
    sample1(argv[1],argv[2],argv[3],argv[4],argv[5]);
    return 0;
}

Output is as follows.

rowKey = 111, field 2 is null [OK]
rowKey = 222, field 1 is null [OK]
rowKey = 222, field 2 is null [NG]
@knonomura
Copy link
Member Author

Corrected output is as follows.

rowKey = 111, field 2 is null [OK]
rowKey = 222, field 1 is null [OK]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant