Главная страница
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.009 c
11-1231103049
haword
2009-01-05 00:04
2011.02.27
Lazarus + MCK KOL + WinCE


2-1291576237
Виктор
2010-12-05 22:10
2011.02.27
о "тонких клиентах"


2-1291622653
Демерго
2010-12-06 11:04
2011.02.27
Дублирование Showmessage


15-1289921196
Делфиец
2010-11-16 18:26
2011.02.27
как соединить два компьютера через 3G модемы


15-1290100289
Mitroshin
2010-11-18 20:11
2011.02.27
Несколько вопросов по переходу с D7 на D2010 (литература)