Главная страница
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-1290029388
Юрий
2010-11-18 00:29
2011.02.27
С днем рождения ! 18 ноября 2010 четверг


2-1291739016
Ux
2010-12-07 19:23
2011.02.27
Ошибка 11004


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


2-1291110259
vegarulez
2010-11-30 12:44
2011.02.27
обновление exe файла


15-1290258354
Константинов
2010-11-20 16:05
2011.02.27
Внешний USB диск не видит ПК что делать?