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

db.describe: add JSON support #4021

Merged
merged 5 commits into from
Aug 19, 2024
Merged

db.describe: add JSON support #4021

merged 5 commits into from
Aug 19, 2024

Conversation

kritibirda26
Copy link
Contributor

Add JSON support to db.describe module. The JSON output looks like:

{
    "table": "mysoils",
    "description": "",
    "insert": null,
    "delete": null,
    "ncols": 7,
    "nrows": 1428,
    "columns": [
        {
            "position": 1,
            "column": "cat",
            "description": "",
            "type": "INTEGER",
            "length": 20,
            "scale": 0,
            "precision": 0,
            "default": null,
            "nullok": true,
            "select": null,
            "update": null
        },
        {
            "position": 2,
            "column": "OBJECTID",
            "description": "",
            "type": "INTEGER",
            "length": 20,
            "scale": 0,
            "precision": 0,
            "default": null,
            "nullok": true,
            "select": null,
            "update": null
        },
        {
            "position": 3,
            "column": "AREA",
            "description": "",
            "type": "DOUBLE PRECISION",
            "length": 20,
            "scale": 0,
            "precision": 0,
            "default": null,
            "nullok": true,
            "select": null,
            "update": null
        },
        {
            "position": 4,
            "column": "PERIMETER",
            "description": "",
            "type": "DOUBLE PRECISION",
            "length": 20,
            "scale": 0,
            "precision": 0,
            "default": null,
            "nullok": true,
            "select": null,
            "update": null
        },
        {
            "position": 5,
            "column": "GSLNC250_",
            "description": "",
            "type": "INTEGER",
            "length": 20,
            "scale": 0,
            "precision": 0,
            "default": null,
            "nullok": true,
            "select": null,
            "update": null
        },
        {
            "position": 6,
            "column": "GSLNC250_I",
            "description": "",
            "type": "INTEGER",
            "length": 20,
            "scale": 0,
            "precision": 0,
            "default": null,
            "nullok": true,
            "select": null,
            "update": null
        },
        {
            "position": 7,
            "column": "GSL_NAME",
            "description": "",
            "type": "CHARACTER",
            "length": 6,
            "scale": 0,
            "precision": 0,
            "default": null,
            "nullok": true,
            "select": null,
            "update": null
        }
    ]
}

Where ??? was used as special string for unknown in plain format, I have changed it to null. For instance, select, update, delete and insert privilege information field.

@github-actions github-actions bot added Python Related code is in Python C Related code is in C HTML Related code is in HTML database Related to database management module docs tests Related to Test Suite labels Jul 10, 2024
@echoix echoix changed the title db.describe: add json support db.describe: add JSON support Jul 10, 2024
db/db.describe/db.describe.html Outdated Show resolved Hide resolved
db/db.describe/db.describe.html Show resolved Hide resolved
db/db.describe/main.c Show resolved Hide resolved
kritibirda26 and others added 2 commits August 4, 2024 22:51
Co-authored-by: Corey White <smortopahri@gmail.com>
@kritibirda26
Copy link
Contributor Author

@cwhite911 the pr is ready for review.

Copy link
Contributor

@cwhite911 cwhite911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@kritibirda26
Copy link
Contributor Author

@echoix can you please merge this PR?

@echoix echoix merged commit 309b417 into OSGeo:main Aug 19, 2024
26 checks passed
@petrasovaa
Copy link
Contributor

Looks like it triggered this:

New defect(s) Reported-by: Coverity Scan
Showing 1 of 1 defect(s)


** CID 1559529:  Memory - illegal accesses  (UNINIT)
/db/db.describe/main.c: 86 in main()


________________________________________________________________________________________________________
*** CID 1559529:  Memory - illegal accesses  (UNINIT)
/db/db.describe/main.c: 86 in main()
80     
81         if (db_describe_table(driver, &table_name, &table) != DB_OK)
82             G_fatal_error(_("Unable to describe table <%s>"),
83                           db_get_string(&table_name));
84     
85         if (!parms.printcolnames)
>>>     CID 1559529:  Memory - illegal accesses  (UNINIT)
>>>     Using uninitialized value "root_object" when calling "print_table_definition".
86             print_table_definition(driver, table, parms.format, root_object,
87                                    cols_array);
88         else {
89             ncols = db_get_table_number_of_columns(table);
90     
91             db_init_string(&stmt);

@kritibirda26 kritibirda26 deleted the db.describe branch August 20, 2024 15:47
kritibirda26 added a commit to kritibirda26/grass that referenced this pull request Aug 20, 2024
@neteler neteler added this to the 8.5.0 milestone Aug 21, 2024
echoix pushed a commit that referenced this pull request Aug 22, 2024
landam pushed a commit to landam/grass that referenced this pull request Aug 22, 2024
* db.describe: add json support

* initialize method args to NULL

* Apply suggestions from code review

Co-authored-by: Corey White <smortopahri@gmail.com>

* update documentation

---------

Co-authored-by: Corey White <smortopahri@gmail.com>
Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com>
landam pushed a commit to landam/grass that referenced this pull request Aug 22, 2024
Mahesh1998 pushed a commit to Mahesh1998/grass that referenced this pull request Sep 19, 2024
* db.describe: add json support

* initialize method args to NULL

* Apply suggestions from code review

Co-authored-by: Corey White <smortopahri@gmail.com>

* update documentation

---------

Co-authored-by: Corey White <smortopahri@gmail.com>
Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com>
Mahesh1998 pushed a commit to Mahesh1998/grass that referenced this pull request Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Related code is in C database Related to database management docs HTML Related code is in HTML module Python Related code is in Python tests Related to Test Suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants