Главная страница
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.48 MB
Время: 0.008 c
8-1180354902
gray_falcon
2007-05-28 16:21
2011.02.27
Помогите с выводом изображения


2-1291306769
Чайник
2010-12-02 19:19
2011.02.27
Вставка в TStringGrid через буфер обмена


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


8-1210633567
Simnet_
2008-05-13 03:06
2011.02.27
FMOD изнутри: как представлен звук в памяти?


6-1235464649
В-В
2009-02-24 11:37
2011.02.27
Как запустить сетевое подключение Windows?