Wow! This is great...I'm not sure I understand it all but when the time comes (in the coming months) I will revisit this post and I may have questions. I'm still not totally comfortable with the farcry method of script writing so this may be more than I'm ready for. I really appreciate the in depth answer. I hope we are able to get the data out of the old system. It's going to be ugly if it can be done and will require some work even if we get it out, to get it ready for import. Thanks again.
Jaci -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jeff Coughlin Sent: Tuesday, March 29, 2005 3:34 PM To: FarCry Developers Subject: [farcry-dev] Re: Importing data into Farcry Jaci Chesnes wrote: > Is there some way to do a batch/semibatch upload of the data directly > into the farcry database. What would I need to consider to do this? There are many ways to tackle this. The question you have to ask yourself is what are you planning on doing with the data? Will some things be used as custom types? Will others just be data? To create data in Farcry (using objectIDs) it is suggested to use the createData() method. In the example below I am importing data to be used for a custom type. --- *Import Script:* (In my example here I'm using MSSQL) The custom type I am creating is called jcRecords and the table is called Records (I'm trying to be generic for this example). Before you do anything, always backup your DB first (you can never be too careful when it comes to DB data). 1. If you are planning on making any custom types I suggest making the custom type CFCs first (and deploy them) so that you have the DB setup (this is also important in case you plan to use an array type. However this example doesn't cover importing data to be used with an array table. Hopefully you can figure it out). Then write a custom script (example below) to import the old data. Make sure to extend farcry types (example: <cfcomponent extends="farcry.farcry_core.packages.types.types" ...> ) Next create an object at the top of the page that refers to the custom type's CFC. <cfset oRecords = createObject('component',application.types.jcRecords.typepath) /> 2. Because we are starting fresh, if you want the DB field names to be different than what they used to be, now is the time to do it (update the new field names in the CFC (and the DB if needed)). When we run the import script we can tell it to import to the new field name(s). 3. Create an import file on your server (example: <project>/www/import/importRecords.cfm). Make sure NOT to leave this here in production :). 3. Query your data from your old DB (in your case I'd suggest importing the old data into temp DB tables to be used for importing). <cfquery name="qOldRecords" datasource="something"> select * from oldRecords </cfquery> 4. Loop over your results. Create a structure each time and add the results to the structure (to be used in the createData() method). If you've created a custom type make sure to account for those new fields. At the end of the loop, send the structure to the createData() method. <cfloop query="qOldRecords"> <cfscript> stRecords = structNew(); // create dynamic data for farcry types stRecords.locked = 0; stRecords.lockedBy = ''; stRecords.label = trim(qOldRecords.title); stRecords.objectID = createUUID(); stRecords.datetimeCreated = now(); stRecords.lastUpdatedBy = 'admin'; stRecords.datetimeLastUpdated = now(); stRecords.createdBy = 'admin'; stRecords.status = 'approved'; // Now add my old data to the new DB stRecords.recordName = qOldRecords.FieldA; stRecords.bestTime = qOldRecords.Best_Time; stRecords.website = qOldRecords.website; /* and so on... */ // Now run the createData method in one of two ways /* This way is cleaner */ oRecords.createData(stRecords); /* Or do it the longer way if you want more control */ stRecords.typeName = 'jcRecords'; oRecords = createobject("component","#application.custompackagepath#.types.#stRecor ds.typeName#"); oRecords.createData(stProperties=stRecords,user='admin'); </cfscript> <cfoutput>Imported record #stRecords.label#.<br /></cfoutput> <cfflush> </cfloop> --- Running these import scripts are slow because we are running a query insert for each loop. However we are only intending to run the script once per import, so we can live with it :). --- This method of import is just one suggestion and works for me. It would be nice if their were an easier way and if we're lucky perhaps someone could share one. Until then I hope this helps. -Jeff C. --- You are currently subscribed to farcry-dev as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] Aussie Macromedia Developers: http://lists.daemon.com.au/ --- You are currently subscribed to farcry-dev as: [email protected] To unsubscribe send a blank email to [EMAIL PROTECTED] Aussie Macromedia Developers: http://lists.daemon.com.au/
