Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2011.02.27;
Скачать: CL | DM;

Вниз

организация кода   Найти похожие ветки 

 
новичок95   (2010-12-06 14:50) [0]

В приложении работающим с БД необходимо проверять значение поля строкового типа (может иметь только 2 значения: section и product). Как с точки зрения организации кода более корректно сделать проверку:

1. написать соответствующие функции:

is_section(const AVal: string): Boolean;
begin
   Result := SameText(AVal, "section");

end;

is_product(const AVal: string): Boolean;
begin
  Result := SameText(AVal, "product");

end;

2. напрямую в коде использовать

SameText(<значение поля>, "section")
SameText(<значение поля>, "products")


 
Dennis I. Komarov ©   (2010-12-06 14:59) [1]


> значение поля строкового типа (может иметь только
> 2 значения: section и product)

Это чего за бред?


 
MonoLife ©   (2010-12-06 15:01) [2]


> is_section(const AVal: string): Boolean;
> begin
>    Result := SameText(AVal, "section");
>
> end;

function result: true = section false= product

имхо, непонятно, зачем в бд держать строковые значения всего для двух значений..достаточно было типа boolean


 
Ega23 ©   (2010-12-06 15:03) [3]

Create Table ...
with Check

CHECK ( expression )

   The CHECK clause specifies an expression producing a Boolean result which new or updated rows must satisfy for an insert or update operation to succeed. Expressions evaluating to TRUE or UNKNOWN succeed. Should any row of an insert or update operation produce a FALSE result an error exception is raised and the insert or update does not alter the database. A check constraint specified as a column constraint should reference that column"s value only, while an expression appearing in a table constraint can reference multiple columns.

   Currently, CHECK expressions cannot contain subqueries nor refer to variables other than columns of the current row.


 
Медвежонок Пятачок ©   (2010-12-06 15:09) [4]

в паскале удобно иметь

type tsometype = (st_unknown,st_section,st_product);

в бд это будет физический инт и ord(tsometypevar)

ну и вместо двух тупых и неудобных  is_section() is_product()

написать одну умную и удобную

function SomeTypeFromString(const Value : string) : TSomeType;


 
12 ©   (2010-12-06 15:12) [5]

таблицу
ID Name
1 "Product"
2 "Section"

join таблицу on таблицу.id =

или left join таблицу on таблицу.id =
where таблицу is (not)null



Страницы: 1 вся ветка

Текущий архив: 2011.02.27;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.009 c
15-1289748125
Sergeant88
2010-11-14 18:22
2011.02.27
Помогите найти компонент


2-1287694639
Ллирик
2010-10-22 00:57
2011.02.27
Offset на строковую константу


2-1291387318
vegarulez
2010-12-03 17:41
2011.02.27
[Twebbrowser+javascript] Получить переменные java


15-1289831257
R_e_T_r_O
2010-11-15 17:27
2011.02.27
Записать из делфи в эксель


2-1290929948
SIV5000
2010-11-28 10:39
2011.02.27
IShellFolder и диалог свойства файлов