知识大全 SQL编程(二)[3]

Posted

篇首语:只要持续地努力,不懈地奋斗,就没有征服不了的东西。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 SQL编程(二)[3]相关的知识,希望对你有一定的参考价值。

DELPHI基础教程:SQL编程(二)[3]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

  Table Open;

  if Table Active then

  Table GetFieldNames(ListBox Items)

  finally

  Screen Cursor := crDefault;

  end;

  end;

  procedure TQueryForm BitBtn Click(Sender: TObject)

  var

  strAlias Alias name selected by the user

  strTable Table name selected by the user

  strField Field name selected by the user

  strValue Field Value entered by the user

  strWhere WHERE clause for the user s query

  strQuote Holds quotes is the query field is text

  strQuery: string; String used to construct the query

  frmQuery: TResultForm; The Results form

  type

   The following type is used with the Type drop down

  list The text values corresponding with each item is

  described in ments along with the relevant SQL operators

  etSQLOps = (soNoCondition not field conditions: no WHERE clause

  soEqual equals: =

  soNotEqual is not equal to: <>

  soLessThan is less than: <

  soLessEqual is less than or equal to: <=

  soMoreThan is greater than: >

  soMoreEqual is greater than or equal to: >=

  soStartsWith starts with: LIKE xx%

  soNoStartsWith doesn t start with: NOT LIKE xx%

  soEndsWith ends with: LIKE %xx

  soNoEndsWith doesn t end with: NOT LIKE %xx

  soContains contains: LIKE %xx%

  soNoContains doesn t contain: NOT LIKE %xx%

  soBlank is blank:

  soNotBlank is not blank:

  soInside contains only: IN ( xx yy zz )

  soOutside) doesn t contain: NOT IN (xx yy zz)

  begin

   Initialize the variables needed to run the query

  with ListBox do

  if ItemIndex = then

  raise Exception Create( Can t Run Query: No Alias Selected )

  else

  strAlias := Items Strings[ItemIndex];

  with ListBox do

  if ItemIndex = then

  raise Exception Create( Can t Run Query: No Table Selected )

  else

  strTable := Items Strings[ItemIndex];

  with ListBox do

  if ItemIndex = then

  begin

  if ComboBox ItemIndex > Ord(soNocondition) then

  raise Exception Create( Can t Run Query: No Field Selected )

  else

  strField := ;

  end

  else

  strField := Items Strings[ItemIndex];

  if (Edit Text = ) and

  (ComboBox ItemIndex > Ord(soNoCondition)) and

  (ComboBox ItemIndex < Ord(soBlank)) then

  raise Exception create( Can t Run Query: No Search Value Entered )

  else

  strValue := Edit Text;

   See if the field being search is a string field If so then pad the

  quote string with quotation marks; otherwise set it to a null value

  if strField <> then

  with Table FieldByName(strField) do

  if (DataType = ftString) or (DataType = ftMemo) then

  strQuote := else

  strQuote := ;

   Construct the WHERE clause of the query based on the user s choice

  in Type

  case etSQLOps(ComboBox ItemIndex) of

  soNoCondition: strWhere := ;

  soEqual: strWhere := strField + = + strQuote + strValue+ strQuote;

  soNotEqual: strWhere := strField + <> + strQuote + strValue +

  strQuote;

  soLessThan: strWhere := strField + < + strQuote + strValue +

  strQuote;

  soLessEqual: strWhere := strField + <= + strQuote + strValue +

  strQuote;

  soMoreThan: strWhere := strField + > + strQuote + strValue +

  strQuote;

  soMoreEqual: strWhere := strField + >= + strQuote + strValue +

  strQuote;

  soStartsWith: strWhere := strField + LIKE + strQuote +

  strValue + % + strQuote;

  soNoStartsWith: strWhere := strField + NOT LIKE + strQuote +

  strValue + % + strQuote;

  soEndsWith: strWhere := strField + LIKE + strQuote +

   % + strValue + strQuote;

  soNoEndsWith: strWhere := strField + NOT LIKE +

  strQuote + % + strValue + strQuote;

  soContains: strWhere := strField + LIKE + strQuote+ % + strValue

  + % + strQuote;

  soNoContains: strWhere := strField + NOT LIKE + strQuote + %

  + strValue + % + strQuote;

  soBlank: strWhere := strField + IS NULL ;

  soNotBlank: strWhere := strField + IS NOT NULL ;

  end;

  if ComboBox ItemIndex = Ord(soNoCondition) then

  strQuery := SELECT * FROM + strTable +

  else if Table FieldByName(strField) DataType = ftString then

  strQuery := SELECT * FROM + strTable + t WHERE t + strWhere

  else

  strQuery := SELECT * FROM + strTable + t WHERE t + strWhere;

   Create an instance of the browser form

  frmQuery := TResultForm Create(Application)

   Use a resource protection block in case an exception is raised This

  ensures that the memory allocated for the Results form is released

  try

  with frmQuery do

cha138/Article/program/Delphi/201311/25142

相关参考

知识大全 SQL编程(二)[4]

DELPHI基础教程:SQL编程(二)[4]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  be

知识大全 SQL编程(二)[2]

DELPHI基础教程:SQL编程(二)[2]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  Ta

知识大全 SQL编程(一)[3]

DELPHI基础教程:SQL编程(一)[3]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  使用

知识大全 动态链接库编程(二)[3]

DELPHI基础教程:动态链接库编程(二)[3]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  

知识大全 SQL编程(一)

SQL编程(一)  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!   SQL语言作为关系数

知识大全 Delphi图形图像编程(二)[3]

DELPHI基础教程:Delphi图形图像编程(二)[3]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一

知识大全 SQL编程(一)[4]

DELPHI基础教程:SQL编程(一)[4]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  利用

知识大全 SQL编程(一)[2]

DELPHI基础教程:SQL编程(一)[2]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  静态

知识大全 SQL编程(一)[1]

DELPHI基础教程:SQL编程(一)[1]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  SQ

知识大全 数据浏览部件的应用及编程(二)[3]

DELPHI基础教程:数据浏览部件的应用及编程(二)[3]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一