Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

Изменение типа поля [D6, Paradox]


Klim Samgin ©   (2003-07-17 08:55:00) 

Здравствуйте, мастера!
Подскажите, как программно изменить тип поля в таблице?
Спасибо.


Sandman25   (2003-07-17 12:29:00) [1]

Johnmen © (17.07.03 12:27)

Не знал. Буду знать.


Johnmen   (2003-07-17 12:27:00) [2]

>Sandman25 © (17.07.03 12:17)

Насколько я в курсе, не обязан поддерживать. И не поддерживает (Paradox).


FOX   (2003-07-17 12:21:00) [3]

Для 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.


Sandman25   (2003-07-17 12:17:00) [4]

Johnmen © (17.07.03 11:36)

Да, но не на Paradox.
Это Ansi SQL-92, Paradox должен его поддерживать.


Плохиш   (2003-07-17 11:50:00) [5]

Для MSSQL:

alter table t alter column a char(15)


Johnmen   (2003-07-17 11:36:00) [6]

>Sandman25 © (17.07.03 10:59)

И это работает ? Проверял ?


VAleksey   (2003-07-17 11:22:00) [7]

Лучше пользуйся SQL.


Sandman25   (2003-07-17 10:59:00) [8]

сreate table t(a int);
alter table t modify a char(15):


chum   (2003-07-17 09:47:00) [9]

Есть функция 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:00) [10]

Есть функция 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.


Klim Samgin   (2003-07-17 09:46:00) [11]

плёхо... :(


Johnmen   (2003-07-17 09:22:00) [12]

А я думаю, что именно так и делает...:)


Klim Samgin   (2003-07-17 09:21:00) [13]

хм-м..
Не думаю, что Database Desktop именно так и делает.
Нужно Short переделать в LongInteger.
Кто ещё что посоветует?


Johnmen   (2003-07-17 09:12:00) [14]

Только заквасить и заново создать...


Наверх

Титульная страница Поиск, карта сайта Написать письмо