Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Базы";
Текущий архив: 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.49 MB
Время: 0.008 c
14-20672
laza admin
2003-07-14 20:15
2003.08.07
Подскажите как работать со словами введенными в edit


14-20741
vidiv
2003-07-20 10:46
2003.08.07
На какие браузеры надо ориентироваться.


14-20763
AlexGreG
2003-07-21 07:03
2003.08.07
... это не значит, что я отказался от Дельфи ...


6-20647
viksoft
2003-05-14 10:25
2003.08.07
Передача файла по UDP - чего то не допонимаю


6-20652
Adventure
2003-05-30 13:13
2003.08.07
как сохранить загруженный рисунок в TWebBrowser на диске.





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский