You can tell your model the path to the existing sqlite database file with something like
db_path = os.path.join('path','to','your','existing.db") #path to wherever you existing DB is db = DAL('sqlite://'+db_path) As for telling it which existing field to use as the ID, as DenesL pointed out if the field isn't already named ID I don't think you can at the moment. If you really want to use the station number (t.staid) as your ID, why not just add a new field called ID to your existing table (using sqlite-browser) and then set the value to match t.staid? Something like UPDATE your_table SET ID = your_table.staid; Now you've got an integer field called ID and web2py should be happy. Well at least as long as you aren't planning on using web2py to add new station entries - I think that it assumes ID is part of a sequence and will automatically assign the next number for you, which wouldn't be the case here. Also, be aware that if you set ID as an integer field (which web2py is going to want) your Station Number of "010010" is going to turn into ID 10010, so watch out if you need those leading zeros to mean something. Are you planning on using web2py to regularly pull in that station list or will it be static once you've taken care of the initial import? If it's static, then the above trick of adding your own ID field should work. If you need to update it regularly with web2py then you might need to keep looking. If necessary you could just bypass the DAL for the inserting and use your own SQL and db.executesql() instead. #untested code #read the contents of csv file into a dictionary csv_contents = csv.DictReader(open(csv_path),dialect='excel') #assumes you've already converted that source HTML doc to CSV #loop through the stations for station in csv_contents: data = [station['Number'], station['Number'], station['Call', station['Name + country/state'], station['Lat'], station['Lon'], station['Elev (meters)']] #notice that station['Number'] is included twice - once for the ID and again for staid db.executesql("""INSERT INTO your_table (ID, staid, stacall, location, lat, lon, elev) VALUES (?, ?, ?, ?, ?, ?, ?)""", data) ~Brian On Dec 9, 5:19 pm, Tim Michelsen <timmichel...@gmx-topmail.de> wrote: > > and create a CSV like this > > > t.staid,t.stacall,t.location,t.state,t.lat,t.lon,t.elev > > 010017,ENFR,FRIGG,NO,5956N,00200E,0 > > 010015,ENBL,FORDE/BRINGELAND,NO,6127N,00552E,0150 > > 010030,,HORNSUND RIVER,NO,7700N,01530E,0012 > > .... > > > note that if elev is missing you must put a 0 (zero). > > Thanks. > > By this appraoch you import the data into the database used by web2py. > What if the data base already exists as a independant sqlite file and I > just want web2py connect to that one? > > How would I show web2py (my model) which field to use as ID? > > Thanks, > Timmie -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.