473,803 Members | 3,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

import SQL statements

Hi, I'm an Access newbie and need to update an Access database from a
web application. I'll need to add new records and also update existing
ones.

What I was thinking of doing is have my web app create a text file with
Access SQL INSERT/UPDATE statements and get Access to import and
execute this file.

Is this possible?

Thanks,
Kevin

Nov 13 '05 #1
16 3295
<kl***@solomon. ie> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
Hi, I'm an Access newbie and need to update an Access database from a
web application. I'll need to add new records and also update existing
ones.

What I was thinking of doing is have my web app create a text file with
Access SQL INSERT/UPDATE statements and get Access to import and
execute this file.

Is this possible?

Thanks,
Kevin

Since this will be a web app then you are not using MS Access at all - you
are only using the same file format (mdb) that Access uses. You don't say
what you are using to build the application, but ASP is a common choice for
working with 'Access databases' but whatever you are using, you this
newsgroup may not be the most appropriate.
Anyway, it doesn't sound like an intermediate text file will bring any
benefits. In ASP for example, the code you write generates and executes the
sql statements directly. If you are really only just starting out with
this, my advice would be to start simple. For example create a database
with one table and two or three columns e.g.
tblPerson: PsnID (Autonumber), PsnFirstName, PsnLastName
Start by creating a web form to add new people to the database. It's a
pretty simple start really, but you may find it takes you longer than you
anticipated.
Nov 13 '05 #2
Hi,

The web app is completly seperate to the Access d/b - it will generate
the update file and the user will simply download it to their local PC
which had access on it. Sorry for not making this clear. The web app is
in PHP/MySQL.

I need to add record to Access,which should be easy, but also update
previsually loaded records in access.

So, I figured I could have my web app create a fileso SQL statements
such as:

insert into mytable values ("a", "b", etc)
update mytable set col_a="c" where id=3

(obvisually incorrect Access syntax, but you get the idea)

Then have Access read the file after the user has downloaded it, and
run the SQL in it.

Can this be done?

Nov 13 '05 #3
<kl***@solomon. ie> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.com...
Hi,

The web app is completly seperate to the Access d/b - it will generate
the update file and the user will simply download it to their local PC
which had access on it. Sorry for not making this clear. The web app is
in PHP/MySQL.

I need to add record to Access,which should be easy, but also update
previsually loaded records in access.

So, I figured I could have my web app create a fileso SQL statements
such as:

insert into mytable values ("a", "b", etc)
update mytable set col_a="c" where id=3

(obvisually incorrect Access syntax, but you get the idea)

Then have Access read the file after the user has downloaded it, and
run the SQL in it.

Can this be done?

OK - I see what you mean. Yes it can be done - this is the sort of thing
Access people do all the time. However creating separate sql statements for
each line would be too ineficient - you should just have the data in the
file.
Since it is your app that is creating the text file you can ensure that it
is of the correct format and this makes things quite easy for you. The
import process could start by creating a linked table to the text file and
then doing something like updating all the rows where you have an existing
id match in the database and then inserting the rest. Try creating a linked
table to a text file - you will then be able to treat the rows as if they
existed in the database.
Nov 13 '05 #4
Hi Justin,

I hear what you say about importing SQL line by line but the
volumeofupates wold be low -less than 50 a week. I think if I could do
this it might be the simplest solution since I know SQL but not Access.

However, I did as you suggest, I made a small text tab delimited file
and imported it to a linked table. Asfor the next step, using that
table to update the main table, I'm at a loss as to what to do next?

Nov 13 '05 #5
<kl***@solomon. ie> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
Hi Justin,

I hear what you say about importing SQL line by line but the
volumeofupates wold be low -less than 50 a week. I think if I could do
this it might be the simplest solution since I know SQL but not Access.

However, I did as you suggest, I made a small text tab delimited file
and imported it to a linked table. Asfor the next step, using that
table to update the main table, I'm at a loss as to what to do next?


Well now you can simply say:
INSERT INTO tblMain (A1, A2) SELECT B1, B2 FROM tblLink

So if you know SQL, inserting the contents of one table into another is done
in one line - rather than writing an insert statement for each line.
Nov 13 '05 #6
Thanks again Justin. I've been playing with the linked table and it
seesm that basically, the entire contents of it are replaced with the
contents of the text file each time I update it using the linked table
manager -is this correct?

How can I do updates of existing records in tblMain? Can it be done
without writing something like a VBA routine? The updated records in
the text file will contain an ID field which exists in tblMain.

Nov 13 '05 #7

kl***@solomon.i e wrote:
Hi, I'm an Access newbie and need to update an Access database from a
web application. I'll need to add new records and also update existing ones.

What I was thinking of doing is have my web app create a text file with Access SQL INSERT/UPDATE statements and get Access to import and
execute this file.

Is this possible?

Thanks,
Kevin


Hi Kevin-

I've been looking at this thread of your and decided to chime in after
some of the things I've read;

Firstly, I import about 450K lines of text into access databases
several times a day from PERL programs, one line at a time and have
no problems (as long as the databases are local and not networked).

If you have a LOT of data (I assume you do) AND you have to network
your Access database- a very valid situation since you're running
a web server, you might want to try this;

1. Create a "dummy" file format in a CSV or TSV file, and set up
a "Link table" entry to this in youe Access database.

2. Write a CGI program (I like Perl- you mught like C# or Python-
whatever) to write this data into your "blank" linked table-
It should be REAL fast and not impact your web server.

You obviously won't beable to index/Key this table, but at least
you'll have it in available to your Access database; I guess after
you load it, you could run an INSERT INTO statement to put it more
permanently into your Access database.

HTH-
kevDot

Nov 13 '05 #8
Hi Kevin,

I'm using PHP and the writing of my text files is no problem. Problem
is I know zero abou Access and as this is a once off thing I want to do
this as easilly /quickly as possible.

I've been able to create the link fileno problem following Justin's
advice and the adding of new records to my main tableis fine (although
I've not tried it yet, but it's asimple SQLstatement).

The problem will be to update existing records. I've been searching
this group and seen a post on a pass-through query - this looks
promising i think. I think I can use this to have my web app write
INSERT/UPDATE statements and run them on Access, is this right?

This app will actually have a small num of records. And it's not
networked, the only connection between web site and Access will be my
client downloading my update file from the site.

Thanks,

Kevin

Nov 13 '05 #9
kl***@solomon.i e wrote in
news:11******** *************@g 44g2000cwa.goog legroups.com:
I'm using PHP and the writing of my text files is no problem.
Problem is I know zero abou Access and as this is a once off thing
I want to do this as easilly /quickly as possible.
I've done exactly what you're describing in the past, including the
PHP part (not me, someone else coding it), though the website db was
MySQL (that was where I concluded that MySQL was a toy database, as
all RI enforcement was in the PHP app, and the app failed to
maintain integrity after an upgrade of the PHP version; the result
was invalid data inserted into the MySQL db (0 in foreign key
fields), and so the update of the Access db failed; but I digress).

Access cannot execute multiple SQL statements. It can only process
one at a time, so you can't just record the SQL that updated the
back end on the website and then have Access run it against the
local file.

Secondly, SQL executed through ODBC against Jet has slightly
different rules than SQL executed native in Access. So, you wouldn't
be able to use the SQL from the website raw -- you'd have to process
it.
I've been able to create the link fileno problem following
Justin's advice and the adding of new records to my main tableis
fine (although I've not tried it yet, but it's asimple
SQLstatement).

The problem will be to update existing records. I've been
searching this group and seen a post on a pass-through query -
this looks promising i think. I think I can use this to have my
web app write INSERT/UPDATE statements and run them on Access, is
this right?
The easiest way to do it in Access is with two recordsets, one for
the source data (downloaded from the website) and one for the local
data:

Dim db As DAO.Database
Dim rs as DAO.Recordset
Dim fld As DAO.Field
Dim strField as String
Dim varNewValue As Variant

Set db = CurrentDB()
Set rsDownload = [SQL for the linked downloaded data]
If rsDownload.Reco rdcount <>0 Then
rsDownload.Move First
Do Until rsDownload.EOF
Set rsLocal = [SQL loading the local record with a WHERE
clause on the PK value of the table]
If rsLocal.Recordc ount = 1 Then
For Each fld In rsDownload.Fiel ds
strField = fld.Name
varNewValue = fld.Value
If Nz(varNewValue) <> Nz(rsLocal(strF ield)) Then
rsLocal.Edit
rsLocal(strFiel d) = varNewValue
rsLocal.Update
End If
Next fld
End If
rsLocal.Close
rsDownload.Move Next
Loop
End If

rsLocal.Close
Set rsLocal = Nothing
rsDownload.Clos e
Set rsDownload = Nothing
Set db = Nothing

Now, you have to be careful about your SQL -- you don't want to
update the PK field, for instance, so you have to exclude it from
both recordsets. There may be other fields that you want to exclued,
as well. You also will want to filter your rsDownload recordset to
include only the records that exist in both tables (an inner join is
the easiest way to do it), since that's the only records that are
going to have updated values.

You also need to use a delete flag to handle deletions and never
actually delete records (just hide them), because, otherwise,
deletions from the web data will never propagate to the local Access
db (if the record is not there, it can't be downloaded and then
deleted).
This app will actually have a small num of records. And it's not
networked, the only connection between web site and Access will be
my client downloading my update file from the site.


It's quite doable, but it works best if it's one-way, from website
to Access database. This means the Access database can't be edited
by the user.

Also, you have to take account of the order of operations in order
not to violate referential integrity. That is, for record additions
to child tables, you must make sure that the additions for the
parent are processed first. If you're actually going to delete the
records flagged as deletes, then you have to delete them in the
child table before deleting them from the parent table.

I would not recommend having no RI on the local Access database,
unless there is reliable RI enforcement on the website db. Indeed,
in the case where the PHP upgrade broke the application-enforced RI
of the MySQL db I was working with, it was only Access's RI
enforcement that informed us of the corrupted data.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2247
by: Matthew Wilson | last post by:
Hi- I'm writing a bunch of classes, several of which need functions and variables defined in the math module. In some instances, I'm going to import my module like this: import myshapes and then in others, I'll do:
2
1509
by: Aahz | last post by:
There were some posts recently discussing whether it's poor style to put import statements inside functions. I recently got reminded that there's one very good reason to avoid it: Python has an import lock that blocks more than one thread from executing import statements. Putting import statements inside functions that might be called in a threaded environment is asking for deadlock trouble. -- Aahz (aahz@pythoncraft.com) ...
4
2196
by: MackS | last post by:
Hi I'm new to Python, I've read the FAQ but still can't get the following simple example working: # file main_mod.py: global_string = 'abc' def main():
1
4174
by: Dennis B. Hansen | last post by:
Hi all... I'm having some problems JAXB compiling som schemas, and was wondering if what i was trying to do is simply wrong... the problem seems to be with my import statements, and I've tried to create a simple example that generates the error (included below). I have two imported schemas, and JAXB seems to only want to import one of them (possibly because they have same namespace (???)).
5
1956
by: ChaosKCW | last post by:
Hi I was wondering if someone could help with the import statements needed to use the timeit module in the following code. I need to access the "cur" object. Thanks, import cx_Oracle import timeit
23
6426
by: Shane Hathaway | last post by:
Here's a heretical idea. I'd like a way to import modules at the point where I need the functionality, rather than remember to import ahead of time. This might eliminate a step in my coding process. Currently, my process is I change code and later scan my changes to make matching changes to the import statements. The scan step is error prone and time consuming. By importing inline, I'd be able to change code without the extra scan...
1
1413
by: Shane Hathaway | last post by:
Let's talk about the problem I really want help with. I brought up a proposal earlier, but it was only half serious. I realize Python is too sacred to accept such a heretical change. ;-) Here's the real problem: maintaining import statements when moving sizable blocks of code between modules is hairy and error prone. I move major code sections almost every day. I'm constantly restructuring the code to make it clearer and simpler, to...
5
1745
by: W. Watson | last post by:
Is there a single source that explains these statements? ------------------------------ from Tkinter import * from Numeric import * import Image import ImageChops import ImageTk import time import binascii import tkMessageBox
3
6122
by: notnorwegian | last post by:
import Tkinter from Tkinter import * i have a program where if i comment out either of those import- statements i get an error. i thought they meant the same thing and from was supposed to be just to imort just a specific function and the * imports everything in the module. but aparently the above statements have diffrent meaning and i cant
1
951
by: Robert Kern | last post by:
Patrick Bouffard wrote: I don't know of any automatic tools. I usually comment out those import statements and use pyflakes to show me the undefined names. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10542
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10309
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7600
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4274
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2968
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.