PC SOFT

PROFESSIONAL NEWSGROUPS
WINDEVWEBDEV and WINDEV Mobile

Home → WINDEV Mobile 2024 → Adding a column to a table
Adding a column to a table
Started by Mirte Vanberghen, Jan., 05 2018 12:39 PM - 1 reply
Posted on January, 05 2018 - 12:39 PM
Hi everyone

Right now I'm working on a app that was originally developed by someone else. Certain things like the database structure are not what they are supposed to be and I'm trying to fix things.

The problem I'm facing is that I need to add a column to a table and the content of the table needs to stay intact.
I found the code to use and when I execute it in SQLLiteStudio, it works perfectly. When I put it in code and try to execute the query, I get the message "Unable to initialize the query, unexpected word: table_info"

This is my code:

gsQlQuery is string =
[
PRAGMA table_info(VItaleParameters)
]

IF HExecuteSQLQuery(DS,hQueryDefault,gsQlQuery) THEN
IF HReadFirst(DS)
IF (HFound(DS)) THEN
IF NOT Contains(DS.Value,"Synched") THEN
/// If field doesn't exist, add to table
gsQlQueryAdd is string =
[
ALTER TABLE VItaleParameters ADD COLUMN 'Synched' INTEGER DEFAULT 0;
]

IF NOT HExecuteSQLQuery(DS,hQueryDefault,gsQlQueryAdd) THEN
Info("Can't add column: " + HError(hErrFullDetails))
END
END
END
END
END

Is there something wrong with my query or is it not possible to check which fields exists in order to add one?
If I just try to execute the adding query, I get the error "bad constant".

Any help would be extremely helpful!!!! I am still very new at Windev ...

Kind regards

Mirte Vanberghen
Posted on January, 05 2018 - 6:42 PM
Hi,

1. You should switch to HFSQL where this kind of problem is managed
automatically (with the hmodifystructure instrcution)

2. if you want to stick to sqllite (your loss), and execute a query that
contains ANYTHING specific to sqllite (no, SQL is NOT standard), then
you should use the hQueryWithoutCorrection parameter (see help)

Best regards
--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

Ready for you: WXShowroom.com, WXReplication (open source) and now WXEDM
(open source)

More information on http://www.fabriceharari.com


Le 1/5/2018 à 6:39 AM, Mirte Vanberghen a écrit :
Hi everyone

Right now I'm working on a app that was originally developed by someone
else. Certain things like the database structure are not what they are
supposed to be and I'm trying to fix things.

The problem I'm facing is that I need to add a column to a table and the
content of the table needs to stay intact.
I found the code to use and when I execute it in SQLLiteStudio, it works
perfectly. When I put it in code and try to execute the query, I get the
message "Unable to initialize the query, unexpected word: table_info"

This is my code:

gsQlQuery is string =
[
    PRAGMA table_info(VItaleParameters)
]

IF HExecuteSQLQuery(DS,hQueryDefault,gsQlQuery) THEN
    IF HReadFirst(DS)         IF (HFound(DS)) THEN
            IF NOT Contains(DS.Value,"Synched") THEN
/// If field doesn't exist, add to table
                gsQlQueryAdd is string =
                [
                    ALTER TABLE VItaleParameters ADD COLUMN 'Synched'
INTEGER DEFAULT 0;
                ]

                IF NOT HExecuteSQLQuery(DS,hQueryDefault,gsQlQueryAdd)
THEN
                    Info("Can't add column: " +
HError(hErrFullDetails))                 END
            END
        END
    END
END

Is there something wrong with my query or is it not possible to check
which fields exists in order to add one?
If I just try to execute the adding query, I get the error "bad constant".

Any help would be extremely helpful!!!! I am still very new at Windev ...

Kind regards

Mirte Vanberghen