Recordset Component in ColdFusion

xiaoxiao2021-03-06  43

http://www.waynedeng.com/blog/showlog.asp?cat_id=25&log_id=500cf The operation of the data is made through CFQuery, which is far more than the recordset in the ASP from the ASP. Object. However, there is an object in ColdFusion MX, we also come to pack a simple Recordset Component!

The following is an application example, familiar with the RecordSet Object, don't understand,? It is easy to operate.

The following is the code: rs = createObject ("Component", "cfnews.model.db.recordset"); rs.getbytable ("article", "article_source"); // Open RecordSource for Article_Source is articles in Article Table WriteOutput (Rs.Getfield ("Title") & "
"); rs.movenext (); Writeoutput (Rs.Getfield ("Title") & "
"); rs.movelast (); Writeoutput (RS.Getfield ("Title") & "
"); // Add a new record rs.addNew (); rs.setfield ("Title", "INSERT TEST"); rs.setfield ("Content "," This is a test "); rs.setfield (" artileid ", 8); rs.setfield (" IMG "," "); rs.Update (); // Modify The second record rs.rownum = 2; rs.setfield ("Title", "Update Test"); rs.Update ();

Below is Recordset.cfc

Cfnews.Model.db.RecordsetComponent Recordset (Recordset Class)

hierarchy: WEB-INF.cftags.component CFNews.model.db.RecordSetpath: C: /Inetpub/wwwroot/CFNews/model/db/RecordSet.cfcproperties: methods: addNew, delete, edit, getBySQL, getByTable, getField, moveFirst, MoveLast, MoveNext, MovePrev, SetField, Update * - Private Method

addNew public addNew () Output: supresseddelete public delete () Output: supressededit public edit () Output: supressedgetBySQL public getBySQL (required string sql, required string recordSource) get a Query object by a sql sentenceOutput: supressedParameters: sql: string, required, sql recordSource: string, required, recordSource getByTable public getByTable (required string tableName, required string recordSource) get a Query object by a table nameOutput: supressedParameters: tableName: string, required, tableName recordSource: string, required, recordSource getField public getField (required string fieldName) get field value by field nameOutput: supressedParameters: fieldName: string, required, fieldName moveFirst public moveFirst () Output: supressedmoveLast public moveLast () Output: supressedmoveNext public moveNext () Output: supressedmovePrev public movePrev () Output: supressedsetField public setField (Required String FieldName, Required String Value, string fieldType) Output: supressedParameters: fieldName: string, required, fieldName value: string, required, value fieldType: string, optional, fieldType update public update (string IDName) Output: supressedParameters: IDName: string, optional, IDName

The following is the code: select * from #this. Tablename # #preservesinglequotes (this.sql) # <

Cffunction name = "getfield" access = "public" output = "false" hint = "get Field value by field name"> structinsertInsertInsertInsert (Evaluate ("this.fields. #"), "Value", arguments.value, "yes");

Name = "RecordsetDelete"> delete from # this.tablename # where #arguments. IDNAME # = # arguments.idname # = Insert Into # this.tablename # (# Fieldslist #) Values ​​( # Comma # ) <

转载请注明原文地址:https://www.9cbs.com/read-59466.html

New Post(0)