Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 10th, 2012, 04:10 AM
icuras icuras is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 165 icuras User rank is Sergeant Major (2000 - 5000 Reputation Level)icuras User rank is Sergeant Major (2000 - 5000 Reputation Level)icuras User rank is Sergeant Major (2000 - 5000 Reputation Level)icuras User rank is Sergeant Major (2000 - 5000 Reputation Level)icuras User rank is Sergeant Major (2000 - 5000 Reputation Level)icuras User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 4 h 42 m 59 sec
Reputation Power: 36
Creating a comma seperated text file from data

I want to create a text file from a DATASET (grid or table). I want to add my own seperator and save it to a location of my own choice. Lets say i have a dbgrid with 30000 records and i need to loop through it this would take ages to export? Am a right? Adding headings should not be a problem but is there a way of knowing the amount of fields in a datatset?So that i can control it dynamically. And can i read the HEADINGS of a datatset or query?

Thanks in advanced?

Reply With Quote
  #2  
Old March 11th, 2012, 05:06 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
This is a huge question that begs its own set of questions
I know because I have done this (partially?) myself.

1. Have you decided which field types you are going to support and
what to do about field types you will not support?
e.g. BLOB fields, other fields that do not override AsString

2. Work with the TDataset and make sure it is not connected to a DB aware grid
or any other GUI components as that will slow down processing dramatically.

3. Take a good look at the TDataset, TFields and TField objects, you will find that they give you access
to all the information you need. But remember item 1. above.
TDataset.FieldCount may NOT be the number of fields you can or want to represent.

4. From 1,3 above - what to do about BLOB fields etc.
Ignore entirely?
Put in default text like <BLOB> (in every row?)?
Put in description <Picture> or <rich text>?

5. How will you format numeric fields?

OK. I could go on for a while; but this is, I hope, enough to get you thinking.
If it leads to more targeted questions then please post a follow up.

Clive

Reply With Quote
  #3  
Old March 14th, 2012, 03:11 AM
icuras icuras is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 165 icuras User rank is Sergeant Major (2000 - 5000 Reputation Level)icuras User rank is Sergeant Major (2000 - 5000 Reputation Level)icuras User rank is Sergeant Major (2000 - 5000 Reputation Level)icuras User rank is Sergeant Major (2000 - 5000 Reputation Level)icuras User rank is Sergeant Major (2000 - 5000 Reputation Level)icuras User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 4 h 42 m 59 sec
Reputation Power: 36
Re

Hallo Clive

Thanks for the Reply. All valid questions. I will have to support blobs. I was thinking of just just using the formats that is in the DATASET. If it is in the table then i know all information is correct. No extra formatting needed. Only thing i have to check obviously is all string or blob fields that there is no commas (,) in the words as it will bugger up my text file if i open it in excel.If you know what i mean. There wil only be text(string), blob, decimal and numbers(integer) and date fields. Nothing fancy.No images or such.

I have a nice export utility that does this for me. Only problem is if i open it in excel each line gets put in the first column. I have emailed the guy that created the component but he said he does not see anything wrong. Somehow i thinkk you shoudl be able to put some kind of character after each line to tell it its a new line? Am i right?

Maybe i will start solong and see what i get? Thanks for your help so far!

Reply With Quote
  #4  
Old March 14th, 2012, 01:18 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
If you are going to support BLOB fields you are, presumably, going to have to consider line lengths if you want it to be viewable.
Also you will need to deal with coding/decoding the BLOB data into Base64, in addition to the issues you mention.

Clive

Reply With Quote
  #5  
Old May 1st, 2012, 11:03 AM
Luthfi Luthfi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 140 Luthfi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 53 m 15 sec
Reputation Power: 2
Quote:
Originally Posted by icuras
I want to create a text file from a DATASET (grid or table). I want to add my own seperator and save it to a location of my own choice. Lets say i have a dbgrid with 30000 records and i need to loop through it this would take ages to export? Am a right?


Before you iterate the records, call the Dataset's DisableControls method. And when you finish iterating, call that Dataset's EnableControls. This way when you are iterating, any linked data aware controls will not be notified about record changing so they don't have to update their "look". This will greatly speed up your iteration.

Quote:
Adding headings should not be a problem but is there a way of knowing the amount of fields in a datatset?


Sure, very easy. For number of fields of a dataset, just check FieldCount property of the Dataset after it is opened. For field names, iterate Fields property of the Dataset.

Quote:
So that i can control it dynamically. And can i read the HEADINGS of a datatset or query?


There is no heading(s) of dataset. The closest thing to it is maybe the fields names. If you are using persistent field. You might want to use/check DisplayLabel property of the persistent field. However DisplayLabel is set manually in design time. It does not get its value from the underlying database.

Quote:
Somehow i thinkk you shoudl be able to put some kind of character after each line to tell it its a new line? Am i right?

For CSV, this char(s) is CR-LF (Carriage Return, #13, and Line Feed, #10). However CR only is usually fine too (especially in unix environment.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Creating a comma seperated text file from data

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap