Форум: "Базы";
Текущий архив: 2003.08.07;
Скачать: [xml.tar.bz2];
ВнизИзменение типа поля Найти похожие ветки
← →
Klim Samgin (2003-07-17 08:55) [0]Здравствуйте, мастера!
Подскажите, как программно изменить тип поля в таблице?
Спасибо.
← →
Johnmen (2003-07-17 09:12) [1]Только заквасить и заново создать...
← →
Klim Samgin (2003-07-17 09:21) [2]хм-м..
Не думаю, что Database Desktop именно так и делает.
Нужно Short переделать в LongInteger.
Кто ещё что посоветует?
← →
Johnmen (2003-07-17 09:22) [3]А я думаю, что именно так и делает...:)
← →
Klim Samgin (2003-07-17 09:46) [4]плёхо... :(
← →
chum (2003-07-17 09:47) [5]Есть функция DbiDoRestructure:
Из справки BDE Api help
C syntax
DBIResult DBIFN DbiDoRestructure (hDb, iTblDescCount, pTblDesc, pszSaveAs, [pszKeyviolName
], [pszProblemsName], bAnalyzeOnly);
Delphi syntax
function DbiDoRestructure (hDb: hDBIDb; iTblDescCount: Word; pTblDesc: pCRTblDesc; pszSaveAs: PChar; pszKeyviolName: PChar; pszProblemsName: PChar; bAnalyzeOnly: Bool): DBIResult stdcall;
Description
DbiDoRestructure changes the properties of a table such as the following: modifying field types or field sizes, adding a field, deleting a field, rearranging fields; or changing indexes, security passwords, or referential integrity.
Parameters
hDb Type: hDBIDb (Input)
Specifies the database handle.
iTblDescCount Type: UINT16 (Input)
Specifies the number of table descriptors. Currently, only one table descriptor can be processed per call, so iTblDescCount must be set to 1.
pTblDesc Type: pCRTblDesc (Input)
Pointer to the client-allocated CRTblDesc structure, which identifies the source table, describes the new record structure (if modified), and lists all other changes to the table
pszSaveAs Type: pCHAR (Input)
Optional. If not NULL, creates a restructured table with this name and leaves the original unchanged.
pszKeyviolName Type: pCHAR (Input)
Optional. Pointer to the Key Violation table name. All records that cause an integrity violation are placed here. If NULL, no Key Violation table is created. If the user supplies a table name, that name is used. If a pointer to an empty string is specified, the table name created is returned in the user"s area (must be at least DBIMAXPATHLEN+1 bytes).
pszProblemsName Type: pCHAR (Input)
Optional. Pointer to the Problems table name. If NULL, no Problems table is created. If the user supplies a table name, that name is used. If the user has overridden the default behavior with a callback, records are placed in a Problems table if they cannot be placed into the destination table without trimming data. If a pointer to an empty string is specified, the table name created is returned in the user"s area (must be at least DBIMAXPATHLEN+1 bytes).
bAnalyzeOnly Type: BOOL (Input)
Not currently used.
Usage
Paradox: For Paradox, after a restructure an application can use the invariant field identification numbers to determine how each column of data has been affected by the restructure.
For example, a form on CUST table displays two fields: CUSTOMER and ADDRESS. A user then restructures the CUST table and adds a new field before CUSTOMER called CUSTOMERID and changes the name of the field CUSTOMER to CUSTOMERNAME. Even though the name and position of the original CUSTOMER field has changed, its invariant field ID does not. When the form is reopened on the table, it can check the cursor property called iRestrVersion, if this has changed since the last time the form was used, it can fetch the field descriptors and use the iFldNum of each field descriptor to fetch the invariant field ID and compare these to the last invariant field IDs fetched before the restructure. This tells the application where each column of data has been moved regardless of any field renaming. Any new fields are given a new invariant field ID and no deleted field"s ID is reused. Care must be taken not to use iFldNum as a field number in this case.
SQL, Access: Not currently supported for SQL or Access.
Prerequisites
The application must specify a completed CRTblDesc structure that defines the modifications to the table.
Completion state
When the restructure completes successfully, the following tables might be created:
· A Key Violations table (if pszKeyviolName was specified integrity violations occurred)
· A Problems table (if pszProblemsName was specified and there was data loss that the client disallowed by a callback)
DbiResult Meaning
DBIERR_NONE A table was successfully generated with the new structure.
Generally, errors returned are due to invalid descriptors or invalid transformations.
← →
chum (2003-07-17 09:47) [6]Есть функция DbiDoRestructure:
Из справки BDE Api help
C syntax
DBIResult DBIFN DbiDoRestructure (hDb, iTblDescCount, pTblDesc, pszSaveAs, [pszKeyviolName
], [pszProblemsName], bAnalyzeOnly);
Delphi syntax
function DbiDoRestructure (hDb: hDBIDb; iTblDescCount: Word; pTblDesc: pCRTblDesc; pszSaveAs: PChar; pszKeyviolName: PChar; pszProblemsName: PChar; bAnalyzeOnly: Bool): DBIResult stdcall;
Description
DbiDoRestructure changes the properties of a table such as the following: modifying field types or field sizes, adding a field, deleting a field, rearranging fields; or changing indexes, security passwords, or referential integrity.
Parameters
hDb Type: hDBIDb (Input)
Specifies the database handle.
iTblDescCount Type: UINT16 (Input)
Specifies the number of table descriptors. Currently, only one table descriptor can be processed per call, so iTblDescCount must be set to 1.
pTblDesc Type: pCRTblDesc (Input)
Pointer to the client-allocated CRTblDesc structure, which identifies the source table, describes the new record structure (if modified), and lists all other changes to the table
pszSaveAs Type: pCHAR (Input)
Optional. If not NULL, creates a restructured table with this name and leaves the original unchanged.
pszKeyviolName Type: pCHAR (Input)
Optional. Pointer to the Key Violation table name. All records that cause an integrity violation are placed here. If NULL, no Key Violation table is created. If the user supplies a table name, that name is used. If a pointer to an empty string is specified, the table name created is returned in the user"s area (must be at least DBIMAXPATHLEN+1 bytes).
pszProblemsName Type: pCHAR (Input)
Optional. Pointer to the Problems table name. If NULL, no Problems table is created. If the user supplies a table name, that name is used. If the user has overridden the default behavior with a callback, records are placed in a Problems table if they cannot be placed into the destination table without trimming data. If a pointer to an empty string is specified, the table name created is returned in the user"s area (must be at least DBIMAXPATHLEN+1 bytes).
bAnalyzeOnly Type: BOOL (Input)
Not currently used.
Usage
Paradox: For Paradox, after a restructure an application can use the invariant field identification numbers to determine how each column of data has been affected by the restructure.
For example, a form on CUST table displays two fields: CUSTOMER and ADDRESS. A user then restructures the CUST table and adds a new field before CUSTOMER called CUSTOMERID and changes the name of the field CUSTOMER to CUSTOMERNAME. Even though the name and position of the original CUSTOMER field has changed, its invariant field ID does not. When the form is reopened on the table, it can check the cursor property called iRestrVersion, if this has changed since the last time the form was used, it can fetch the field descriptors and use the iFldNum of each field descriptor to fetch the invariant field ID and compare these to the last invariant field IDs fetched before the restructure. This tells the application where each column of data has been moved regardless of any field renaming. Any new fields are given a new invariant field ID and no deleted field"s ID is reused. Care must be taken not to use iFldNum as a field number in this case.
SQL, Access: Not currently supported for SQL or Access.
Prerequisites
The application must specify a completed CRTblDesc structure that defines the modifications to the table.
Completion state
When the restructure completes successfully, the following tables might be created:
· A Key Violations table (if pszKeyviolName was specified integrity violations occurred)
· A Problems table (if pszProblemsName was specified and there was data loss that the client disallowed by a callback)
DbiResult Meaning
DBIERR_NONE A table was successfully generated with the new structure.
Generally, errors returned are due to invalid descriptors or invalid transformations.
← →
Sandman25 (2003-07-17 10:59) [7]сreate table t(a int);
alter table t modify a char(15):
← →
VAleksey (2003-07-17 11:22) [8]Лучше пользуйся SQL.
← →
Johnmen (2003-07-17 11:36) [9]>Sandman25 © (17.07.03 10:59)
И это работает ? Проверял ?
← →
Плохиш (2003-07-17 11:50) [10]Для MSSQL:
alter table t alter column a char(15)
← →
Sandman25 (2003-07-17 12:17) [11]Johnmen © (17.07.03 11:36)
Да, но не на Paradox.
Это Ansi SQL-92, Paradox должен его поддерживать.
← →
FOX (2003-07-17 12:21) [12]Для Paradox:
FieldShort-старое поле типа Short.
TmpField-промежуточное поле.
LongIntegerField-новое поле с типом LongInteger
1. ALTER TABLE Test ADD TmpField INTEGER
2. UPDATE Test SET TmpField = CAST(FieldShort AS INTEGER)
3. ALTER TABLE Test DROP FieldShort, ADD LongIntegerField INTEGER
4. UPDATE Test SET LongIntegerField=TmpField.
← →
Johnmen (2003-07-17 12:27) [13]>Sandman25 © (17.07.03 12:17)
Насколько я в курсе, не обязан поддерживать. И не поддерживает (Paradox).
← →
Sandman25 (2003-07-17 12:29) [14]Johnmen © (17.07.03 12:27)
Не знал. Буду знать.
Страницы: 1 вся ветка
Форум: "Базы";
Текущий архив: 2003.08.07;
Скачать: [xml.tar.bz2];
Память: 0.48 MB
Время: 0.009 c