Hot Topic (More than 10 Replies) Importing data...Help needed... (Read 2614 times)
Cliff
Full Member
***
Offline



Posts: 126
Location: New Hampshire
Joined: May 5th, 2006
Importing data...Help needed...
Jan 2nd, 2007 at 5:29pm
Print Post Print Post  
I have successfully created the file structures I need to import into Sesame from a couple qa databases we want to retire...

However, the database file is very large and spans several sheets in an excel workbook (on the order of 800 or so fields/columns).

Of course, excel can not export to csv from the several sheeted file.

I can however, export each sheet to a discreet csv file.  Is it possible to import each discreet csv file into my new Sesame database?

All help is very much appreciated.

Thank you...
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Importing data...Help needed...
Reply #1 - Jan 2nd, 2007 at 5:51pm
Print Post Print Post  
Cliff wrote on Jan 2nd, 2007 at 5:29pm:
Is it possible to import each discreet csv file into my new Sesame database?


You can import multiple files but each import will create a new set of records. You cannot use import to "merge" the data in one CSV file with records created by importing a different file.

You can use the File I/O commands in SBasic to manually create records using the data from both files. You can also use SBasic File I/O to blend the two CSV files into a single import file, assuming there is a one-to-one match between the records in each file.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Cliff
Full Member
***
Offline



Posts: 126
Location: New Hampshire
Joined: May 5th, 2006
Re: Importing data...Help needed...
Reply #2 - Jan 2nd, 2007 at 8:21pm
Print Post Print Post  
Thanks Hammer...

Another question if I may...can you point me in the general direction of where I may find an overview or other tutorialesqe information that may help me slog through this?

Again...thanks...

Cliff
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Importing data...Help needed...
Reply #3 - Jan 2nd, 2007 at 8:31pm
Print Post Print Post  
Not really a tutorial, but here is an example of doing something very similar:

http://www.lantica.com/Forum3/cgi-bin/yabb2/YaBB.pl?num=1165960584/
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Cliff
Full Member
***
Offline



Posts: 126
Location: New Hampshire
Joined: May 5th, 2006
Re: Importing data...Help needed...
Reply #4 - Jan 2nd, 2007 at 9:08pm
Print Post Print Post  
Sorry but I am at a loss here...

I have 5 csv files with approximately 4000 records in approximately 700 fields.  Are you telling me that I have to code this "merge" operation for each field?

Also, how can I access these different csv files in "one shot" in the Sesame program window?

There has to be an easier way to do this...I hope...
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Importing data...Help needed...
Reply #5 - Jan 2nd, 2007 at 9:22pm
Print Post Print Post  
Cliff wrote on Jan 2nd, 2007 at 9:08pm:
Sorry but I am at a loss here...

I have 5 csv files with approximately 4000 records in approximately 700 fields.  Are you telling me that I have to code this "merge" operation for each field?


No, not at all.

Quote:
Also, how can I access these different csv files in "one shot" in the Sesame program window?


The example accesses 2 different csv fiiles and combines them into one. You will need to adapt it so that it accesses 5 csv files and combines them into one. Your best bet is to use a mass update on one record. Just write the program in any element, it doesn't matter which. Make sure you only have one record (Add mode will get you that).

Quote:
There has to be an easier way to do this...I hope...


Adapt the example so that it combines all five of your csv files into one csv file. Import the resulting csv file, paying attention to the field order the csv file has.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Cliff
Full Member
***
Offline



Posts: 126
Location: New Hampshire
Joined: May 5th, 2006
Re: Importing data...Help needed...
Reply #6 - Jan 2nd, 2007 at 9:37pm
Print Post Print Post  
Thanks...apologies for my panic! Embarrassed

I am currently finishing work to ensure that I have a one-to-one match between the records in each file between the csv's I plan to import and the Sesame form structure. 

I won't be ready to merge these data files for about a week or so.

Would you be willing to take a look at my code before I launch?

Cliff
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Importing data...Help needed...
Reply #7 - Jan 2nd, 2007 at 9:40pm
Print Post Print Post  
Cliff wrote on Jan 2nd, 2007 at 9:37pm:
Thanks...apologies for my panic! Embarrassed

I am currently finishing work to ensure that I have a one-to-one match between the records in each file between the csv's I plan to import and the Sesame form structure. 

I won't be ready to merge these data files for about a week or so.

Would you be willing to take a look at my code before I launch?

Cliff



Absolutely. I'd be happy to look at your code. I am working on an example that is closer to your case as we speak.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Importing data...Help needed...
Reply #8 - Jan 2nd, 2007 at 9:53pm
Print Post Print Post  
Here is an example that is closer to what you are doing.
Code
Select All
var fh1 as int
var fh2 as int
var fh3 as int
var fh4 as int
var fh5 as int
var fh_out as int

var done as int

var str1 as string
var str2 as string
var str3 as string
var str4 as string
var str5 as string
var str_out as string

	fh1 = fileOpen("t1.txt")
	fh2 = fileOpen("t2.txt")
	fh3 = fileOpen("t3.txt")
	fh4 = fileOpen("t4.txt")
	fh5 = fileOpen("t5.txt")

	fh_out = fileOpen("OutFile.txt")
	fileSeek(fh1, 0)
	fileSeek(fh2, 0)
	fileSeek(fh3, 0)
	fileSeek(fh4, 0)
	fileSeek(fh5, 0)
	fileSeek(fh_out, 0)

	done = 0
	while(done = 0)
	{
		fileReadln(fh1, str1)
		fileReadln(fh2, str2)
		fileReadln(fh3, str3)
		fileReadln(fh4, str4)
		fileReadln(fh5, str5)

		if((@Len(str1) > 0) and (@Len(str2) > 0) and (@Len(str3) > 0) and (@Len(str4) > 0) and (@Len(str5) > 0))
		{
			str_out = str1 + ", " + str2 + ", " + str3 + ", " + str4 + ", " + str5
			fileWriteln(fh_out, str_out)
		}
		else
		{
			done = 1
		}
	}
	fileClose(fh_out)
	fileClose(fh5)
	fileClose(fh4)
	fileClose(fh3)
	fileClose(fh2)
	fileClose(fh1)
  

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Importing data...Help needed...
Reply #9 - Jan 2nd, 2007 at 10:02pm
Print Post Print Post  
To use the code above, cut&paste the code into any element in a mass update for one record. Make sure that the mass update will only run on one record! If it runs more than once it will double up your data - not good. Replace the filenames in the code as needed. It will create a big file will one row for each of your records, comprising fields from each of the five input files concatenated in the order in which they appear in the input files. Each of the five input files must have the exact same number of lines. The program will stop when it hits a blank line or end of file in any of the five.

After the code runs, you will need to run an ASCII import on the big resulting file. Make sure that the elements in your import spec match the order that they appear in the file. If not, drag the elements in the spec (hint: use SHIFT-Up / Down keys) to get them in the needed order in the spec.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Cliff
Full Member
***
Offline



Posts: 126
Location: New Hampshire
Joined: May 5th, 2006
Re: Importing data...Help needed...
Reply #10 - Jan 9th, 2007 at 5:39pm
Print Post Print Post  
Just got back in to work on this project and want to say WOW!...

Thanks a million...plus...

I very much appreciate your taking the time to assist with this for me...

I'll give this a "whirl" and will keep you posted.

Again...

Thanks...

Cliff Normand
  
Back to top
 
IP Logged
 
Cliff
Full Member
***
Offline



Posts: 126
Location: New Hampshire
Joined: May 5th, 2006
Re: Importing data...Help needed...
Reply #11 - Jan 9th, 2007 at 9:34pm
Print Post Print Post  
Hi Mark:

Tried but no cigar...

What I did:

1. manually parsed through each csv text file to ensure its one to one veracity with my Sesame form
2. saved each of the 3 files into my Sesame data directory
3. opened a backup copy of the form in Sesame plus
4. selected one record upon which to affect a mass update
5. copied and pasted the following code into a blank element within that record
6. ran mass update...poof...nothing happened...no errors...no grinding hard disc...
7. checked data directory for any evidence of any file of any size having been created...none...

I modified the code you sent me as I have only 3 text files to deal with...code follows...again...Thanks...!!

var fh1 as int
var fh2 as int
var fh3 as int
var fh_out as int

var done as int

var str1 as string
var str2 as string
var str3 as string
var str_out as string

     fh1 = fileOpen("book1.txt")
     fh2 = fileOpen("book2.txt")
     fh3 = fileOpen("book3.txt")

     fh_out = fileOpen("OutFile.txt")
     fileSeek(fh1, 0)
     fileSeek(fh2, 0)
     fileSeek(fh3, 0)
     fileSeek(fh_out, 0)

     done = 0
     while(done = 0)
     {
           fileReadln(fh1, str1)
           fileReadln(fh2, str2)
           fileReadln(fh3, str3)

           if((@Len(str1) > 0) and (@Len(str2) > 0) and (@Len(str3) > 0) and (@Len(str4) > 0) and (@Len(str5) > 0))
           {
                 str_out = str1 + ", " + str2 + ", " + str3 + ", " + str4 + ", " + str5
                 fileWriteln(fh_out, str_out)
           }
           else
           {
                 done = 1
           }
     }      
     fileClose(fh_out)
     fileClose(fh3)
     fileClose(fh2)
     fileClose(fh1)


  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Importing data...Help needed...
Reply #12 - Jan 9th, 2007 at 10:02pm
Print Post Print Post  
Just at a glance, the code snippet below:

Code
Select All
	while(done = 0)
     {
	     fileReadln(fh1, str1)
	     fileReadln(fh2, str2)
	     fileReadln(fh3, str3)

	     if((@Len(str1) > 0) and (@Len(str2) > 0) and (@Len(str3) > 0) and (@Len(str4) > 0) and (@Len(str5) > 0))
	     {
		     str_out = str1 + ", " + str2 + ", " + str3 + ", " + str4 + ", " + str5
		     fileWriteln(fh_out, str_out)
	     }
	     else
	     {
		     done = 1
	     }
     }
 



is reading in three lines, but checking the length and trying to concatenate five.

Try altering it so it is consistently either three or five:
Code
Select All
	while(done = 0)
     {
	     fileReadln(fh1, str1)
	     fileReadln(fh2, str2)
	     fileReadln(fh3, str3)

	     if((@Len(str1) > 0) and (@Len(str2) > 0) and (@Len(str3) > 0))
	     {
		     str_out = str1 + ", " + str2 + ", " + str3
		     fileWriteln(fh_out, str_out)
	     }
	     else
	     {
		     done = 1
	     }
     }
 



BTW - the code as you pasted it here, doesn't compile because you are using at least two variables that were declared in my example, but when you went from five to three lines, you deleted the declarations for two of them (str4 and str5).

Also - especially important: when you write a Mass Update, you do not put the code directly into the element. You need to put the code into the programming editor. Instructions for writing and running a mass update start on page 264 of the manual.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Cliff
Full Member
***
Offline



Posts: 126
Location: New Hampshire
Joined: May 5th, 2006
Re: Importing data...Help needed...
Reply #13 - Jan 30th, 2007 at 9:23pm
Print Post Print Post  
Hi Mark:

It is I, your diligent, if not frustrated student...

Thanks for pointing me in the direction of where to begin to look in the user manual for assistance.

While it was helpful in shedding light on what it is I am trying to accomplish, and most importantly how, I am still not able to concatenate my data files together.

I have manually parsed through my three data files in Excel several times to ensure a one to one correlation between them and my Sesame form. As above, I have read and re-read the sections in the manual dealing with data sorting and mass update and have followed the instructions for mass update to a “T” at least half a dozen times.

I have also edited the code you so kindly provided me to behave as it should...however, when I run the mass update it parses through record one (of 3044) and freezes on record 2. 

Interestingly enough I do generate an “outfile.txt” file, however, if I let the process run after it appears to freeze the file continues to grow to over a gig and a quarter in size though my three (discrete) data files are 2.1MB, 1.2MB, and 1.2MB in size.

I am doing my best to accomplish due diligence and do not want to impose further...but...

Do you have any suggestions?  This project needs to be completed soon as I am a couple months behind schedule at present.

Any and all help is very much appreciated.

Thanks again...

Cliff

"My" code follows:

var fh1 as int
var fh2 as int
var fh3 as int
var fh_out as int

var done as int

var str1 as string
var str2 as string
var str3 as string
var str_out as string

     fh1 = fileOpen("book1.txt")
     fh2 = fileOpen("book2.txt")
     fh3 = fileOpen("book3.txt")

     fh_out = fileOpen("OutFile.txt")
     fileSeek(fh1, 0)
     fileSeek(fh2, 0)
     fileSeek(fh3, 0)
     fileSeek(fh_out, 0)

     done = 0
     while(done = 0)
     {
          fileReadln(fh1, str1)
          fileReadln(fh2, str2)
          fileReadln(fh3, str3)

          if((@Len(str1) > 0) and (@Len(str2) > 0) and (@Len(str3) > 0))
          {
                str_out = str1 + ", " + str2 + ", " + str3
                fileWriteln(fh_out, str_out)
     }
     else
     {
                done = 1
     }
     }
     fileClose(fh_out)
     fileClose(fh3)
     fileClose(fh2)
     fileClose(fh1)
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Importing data...Help needed...
Reply #14 - Jan 30th, 2007 at 9:36pm
Print Post Print Post  
Cliff,
From your description of what is happening, it sounds like you are running the mass update on more than one record. It is very important that you run the mass update on one and only one record. To accomplish this, go into your form in add mode, put some fake data in, hit F10, hit F9, do your mass update. You may then delete (F3) the one fake record.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Importing data...Help needed...
Reply #15 - Jan 30th, 2007 at 10:29pm
Print Post Print Post  
Hello Cliff,

Give the following code a try.

Code
Select All
var fh1 as int
var fh2 as int
var fh3 as int
var fh_out as int
var done as int
var str1 as string
var str2 as string
var str3 as string
var str_out as string

	fh1 = fileOpen("book1.txt")
	fh2 = fileOpen("book2.txt")
	fh3 = fileOpen("book3.txt")

	fh_out = fileOpen("OutFile.txt")
	fileSeek(fh1, 0)
	fileSeek(fh2, 0)
	fileSeek(fh3, 0)
	fileSeek(fh_out, 0)

	done = 0
	While(done = 0)
	{
		If FilePos(fh1) <> FileSize(fh1) Then
		{
			fileReadln(fh1, str1)
		}
		Else
		{
			str1 = ""
		}
		If FilePos(fh2) <> FileSize(fh2) Then
		{
			fileReadln(fh2, str2)
		}
		Else
		{
			str2 = ""
		}
		If FilePos(fh3) <> FileSize(fh3) Then
		{
			fileReadln(fh3, str3)
		}
		Else
		{
			str3 = ""
		}

		If((@Len(str1) > 0) and (@Len(str2) > 0) and (@Len(str3) > 0))
		{
			str_out = str1 + ", " + str2 + ", " + str3
			fileWriteln(fh_out, str_out)
		}
		Else
		{
			done = 1
		}
	}
	fileClose(fh_out)
	fileClose(fh3)
	fileClose(fh2)
	fileClose(fh1) 



-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Cliff
Full Member
***
Offline



Posts: 126
Location: New Hampshire
Joined: May 5th, 2006
Re: Importing data...Help needed...
Reply #16 - Feb 16th, 2007 at 8:00pm
Print Post Print Post  
Hi Ray:

I want to thank you very much for helping me out.
I was able to develop my "outfile" this last Tuesday and have yet to try to import same into my test form.
However, base on my experience with the export I am betting that all will be fine.

I will update you with our success story.

Again...

Thanks!

Cliff
  
Back to top
 
IP Logged