Вниз
Скачать: 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 вся ветка

Скачать: CL | DM;



Память: 0.46 MB
Время: 0.005 c
15-1289831257
R_e_T_r_O
2010-11-15 17:27
2011.02.27
Записать из делфи в эксель


6-1201379773
Max.66RUS
2008-01-26 23:36
2011.02.27
Отправка файла POST-запросом...


2-1291636226
новичок95
2010-12-06 14:50
2011.02.27
организация кода


2-1291296114
privet123
2010-12-02 16:21
2011.02.27
Способ прочитать с диска - правильно так?


4-1245770042
lexik
2009-06-23 19:14
2011.02.27
Иконка в Tray без окна. (Без VCL)




   Наверх