473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Exporting jet table metadata as text?

Hi all--

In an attempt to commit an Access MDB to a versioning system (subversion),
I'm trying to figure out how to convert a jet table's metadata to text, a
la SaveAsText. The end goal is to be able to build an MDB completely from
the svn repository text files.

Has anybody dealt with this?

Thanks in advance,
Kevin
Feb 27 '06 #1
6 3668
On Mon, 27 Feb 2006 01:47:16 -0800, Kevin Chambers <My********@MyName.DontSpamMe.UncleSam> wrote:
Hi all--

In an attempt to commit an Access MDB to a versioning system (subversion),
I'm trying to figure out how to convert a jet table's metadata to text, a
la SaveAsText. The end goal is to be able to build an MDB completely from
the svn repository text files.

Has anybody dealt with this?

Thanks in advance,
Kevin

This is a metareply I'm afraid.
You can go some way using SQL create table statements including indexes and relationships but this
won't handle all the properties and for your purposes would ultimately be a waste of time.
I would use code which enumerates all properties in DAO (others might use ADOX if that can handle
all the properties). There are a lot of properties which in practice are set by default but it would
be simpler to store them all. Don't forget that some properties cannot be read (trap this error and
ignore them) and that to handle custom properties (which include field descriptions) you will
require the fully extended syntax ...xxx.properties("yyy"). To rebuild you would need to do things
in the right order. (ie tables before foreign keys).

Maybe someone has done this - XML would be a good output notation.

A much easier way would be to have the tables in SQL server or some other db where you can generate
them from a script!
Feb 27 '06 #2
polite person wrote:
On Mon, 27 Feb 2006 01:47:16 -0800, Kevin Chambers <My********@MyName.DontSpamMe.UncleSam> wrote:
Hi all--

In an attempt to commit an Access MDB to a versioning system (subversion),
I'm trying to figure out how to convert a jet table's metadata to text, a
la SaveAsText. The end goal is to be able to build an MDB completely from
the svn repository text files.

Has anybody dealt with this?

Thanks in advance,
Kevin

This is a metareply I'm afraid.
You can go some way using SQL create table statements including indexes and relationships but this
won't handle all the properties and for your purposes would ultimately be a waste of time.
I would use code which enumerates all properties in DAO (others might use ADOX if that can handle
all the properties). There are a lot of properties which in practice are set by default but it would
be simpler to store them all. Don't forget that some properties cannot be read (trap this error and
ignore them) and that to handle custom properties (which include field descriptions) you will
require the fully extended syntax ...xxx.properties("yyy"). To rebuild you would need to do things
in the right order. (ie tables before foreign keys).

Maybe someone has done this - XML would be a good output notation.

A much easier way would be to have the tables in SQL server or some other db where you can generate
them from a script!


Thanks for the reply, pp

Yes, that's all pretty much what I had in mind. I thought about creating
DDL statements like you say, but wanted to be able to capture all the odd
little jet properties. As I write, though, I realize that there may
substantial advantage in avoiding all the Jet-specific stuff anyways.

I've already written code to synchronize schemas in DAO, so I have an idea
of what's involved on that end. I was wondering if anyone has written the
code to do the text export and then parsing of the text for import.

XML is OK, but also annoyingly verbose for my tastes. I suppose I could
mimic the format of the SaveAsText format, then I'd have something I could
reuse if I ever needed to rebuild a form/report/etc programmatically.

Feb 27 '06 #3
On Mon, 27 Feb 2006 13:38:25 -0800, Kevin Chambers <My********@MyName.DontSpamMe.UncleSam> wrote:
polite person wrote:
On Mon, 27 Feb 2006 01:47:16 -0800, Kevin Chambers <My********@MyName.DontSpamMe.UncleSam> wrote:
Hi all--

In an attempt to commit an Access MDB to a versioning system (subversion),
I'm trying to figure out how to convert a jet table's metadata to text, a
la SaveAsText. The end goal is to be able to build an MDB completely from
the svn repository text files.

Has anybody dealt with this?

Thanks in advance,
Kevin

This is a metareply I'm afraid.
You can go some way using SQL create table statements including indexes and relationships but this
won't handle all the properties and for your purposes would ultimately be a waste of time.
I would use code which enumerates all properties in DAO (others might use ADOX if that can handle
all the properties). There are a lot of properties which in practice are set by default but it would
be simpler to store them all. Don't forget that some properties cannot be read (trap this error and
ignore them) and that to handle custom properties (which include field descriptions) you will
require the fully extended syntax ...xxx.properties("yyy"). To rebuild you would need to do things
in the right order. (ie tables before foreign keys).

Maybe someone has done this - XML would be a good output notation.

A much easier way would be to have the tables in SQL server or some other db where you can generate
them from a script!


Thanks for the reply, pp

Yes, that's all pretty much what I had in mind. I thought about creating
DDL statements like you say, but wanted to be able to capture all the odd
little jet properties. As I write, though, I realize that there may
substantial advantage in avoiding all the Jet-specific stuff anyways.

I've already written code to synchronize schemas in DAO, so I have an idea
of what's involved on that end. I was wondering if anyone has written the
code to do the text export and then parsing of the text for import.

XML is OK, but also annoyingly verbose for my tastes. I suppose I could
mimic the format of the SaveAsText format, then I'd have something I could
reuse if I ever needed to rebuild a form/report/etc programmatically.


Export table design to text (XML) example is at
http://groups.google.co.uk/group/mic...d5ffafa5abdd30

More googling (or putting in some work!) might find import, and similar code for relations

I agree the DDL route seems better but it depends on the purpose of your backup. The only really
useful things not in (IMHO) are field/table description properties as most of the others are
formatting etc including the lunatic caption property.
Some time ago I wrote something one-off to convert JET to db2 and what follows is modified from
that, without much testing I'm afraid. Include the module in your DB and call the sub
CreateTableQueries. Output DDL is written to a file TEST.TXT and can be pasted into a module in an
empty database and run to recreate the tables of the original database (design only).
One property not captured is if your autonumbers are random.

Option Compare Database
Option Explicit

Dim outfile&

Public Sub CreateTableQueries()
Dim mydb As DATABASE
Dim mytdef As TableDef
Set mydb = CurrentDb
openoutfile
For Each mytdef In mydb.TableDefs
If Left(mytdef.name, 4) <> "MSys" Then
CreateOneTable mytdef
CreateIndexes mytdef
End If
Next
DoRelations mydb
closeoutfile
End Sub

Public Sub CreateOneTable(mytdef As TableDef)
Dim myfld As Field, fld2 As Field
Dim myindex As Index
Dim mysql$, Tablename$, sepcode$, a$

Tablename = mytdef.name
mysql = "CREATE TABLE " & sanitary(Tablename) & " ("
sepcode = ""
For Each myfld In mytdef.Fields
mysql = mysql & sepcode & sanitary(myfld.name) & " "
Select Case myfld.Type
Case dbBoolean 'Boolean
a = "YESNO"
Case dbByte 'Boolean
a = "BYTE"
Case dbCurrency 'Currency
a = "CURRENCY"
Case dbDate 'Date / Time
a = "DATE"
Case dbDouble 'Double
a = "DOUBLE"
Case dbInteger 'Integer
a = "INTEGER"
Case dbLong 'Long
'test if counter, doesn't detect random property if set
If (myfld.Attributes And dbAutoIncrField) Then
a = "COUNTER"
Else
a = "LONG"
End If
Case dbMemo 'Memo
a = "MEMO"
Case dbSingle 'Single
a = "SINGLE"
Case dbText 'Text
a = "TEXT(" & myfld.Size & ")"
Case dbGUID 'Text
a = "GUID"
Case Else
MsgBox "Field " & Tablename & "." & myfld.name & " of type " & myfld.Type & " has
been ignored!!!"
End Select
mysql = mysql & a
If myfld.Required Then
mysql = mysql & " NOT NULL "
End If
sepcode = ", "
Next myfld
plant mysql & ")"
End Sub

Public Sub CreateIndexes(mytdef As TableDef)
Dim myfld As Field
Dim myindex As Index
Dim mysql$, a$, sepcode$, Tablename$

Tablename = mytdef.name
For Each myindex In mytdef.Indexes
If Left(myindex.name, 1) = "{" Then
'ignore, GUID-type indexes - bugger them
ElseIf myindex.Foreign Then
'do from relationships
Else
sepcode = ""
mysql = "CREATE "
If myindex.Unique Then
mysql = mysql & "UNIQUE "
End If
mysql = mysql & "INDEX " & myindex.name & " ON " & sanitary(mytdef.name) & "("
For Each myfld In myindex.Fields
mysql = mysql & sepcode & sanitary(myfld.name)
sepcode = ", "
Next myfld
mysql = mysql & ")"
If myindex.Primary Or myindex.IgnoreNulls Or myindex.Required Then
mysql = mysql & " WITH "
If myindex.Primary Then mysql = mysql & "PRIMARY "
If myindex.IgnoreNulls Then mysql = mysql & "IGNORE NULL "
If myindex.Required Then mysql = mysql & "DISALLOW NULL "
End If
plant mysql
End If
Next myindex

End Sub

Public Sub DoRelations(mydb As DATABASE)
Dim mytdef As TableDef
Dim myrel As Relation
Dim myfld As Field
Dim myindex As Index
Dim mysql$, a$, sepcode$, constraintname$

'ALTER TABLE table
'CONSTRAINT name
'FOREIGN KEY (ref1[, ref2 [, ...]]) REFERENCES foreigntable [(foreignfield1 [, foreignfield2 [,
....]])]

Set mydb = CurrentDb
For Each myrel In mydb.Relations
With myrel
constraintname = sanitary(.name) 'may be a guid string
mysql = "ALTER TABLE " & .ForeignTable & " ADD CONSTRAINT " & constraintname & " FOREIGN
KEY ("
sepcode = ""
For Each myfld In .Fields 'ie fields of the relation
mysql = mysql & sepcode & sanitary(myfld.ForeignName)
sepcode = ","
Next
mysql = mysql & ") REFERENCES " & .Table & "("
sepcode = ""
For Each myfld In .Fields
mysql = mysql & sepcode & sanitary(myfld.name)
sepcode = ","
Next
mysql = mysql & ")"
End With
plant mysql
Next
End Sub

Public Function sanitary(NameWithOddChars$) As String
'this is here because original prog converted to non-JET dbs
'so some character substitutions were made in names
sanitary = "[" & NameWithOddChars & "]"
End Function

Public Function str1tostr2(f$, a$, b$)
'in string F, replaces A by B wherever it occurs
'needed in Access 97 as no built-in function
Dim i&
i = InStr(f, a) - 1
If i >= 0 Then
str1tostr2 = Left(f, i) & b & str1tostr2(Right(f, Len(f) - i - Len(a)), a, b)
Else
str1tostr2 = f
End If
End Function

Public Sub plant(s$)
If Len(s) > 0 Then
Print #outfile, "CurrentDb.Execute """ & s & """"
End If
End Sub

Public Sub openoutfile()
outfile = FreeFile
Open "TEST.TXT" For Output As #outfile
Print #outfile, "Sub RunMe()"
End Sub

Public Sub closeoutfile()
Print #outfile, "End Sub"
Close #outfile
End Sub

Feb 28 '06 #4
polite person wrote:
On Mon, 27 Feb 2006 13:38:25 -0800, Kevin Chambers <My********@MyName.DontSpamMe.UncleSam> wrote:
polite person wrote:
On Mon, 27 Feb 2006 01:47:16 -0800, Kevin Chambers <My********@MyName.DontSpamMe.UncleSam> wrote:

Hi all--

In an attempt to commit an Access MDB to a versioning system (subversion),
I'm trying to figure out how to convert a jet table's metadata to text, a
la SaveAsText. The end goal is to be able to build an MDB completely from
the svn repository text files.

Has anybody dealt with this?

Thanks in advance,
Kevin
This is a metareply I'm afraid.
You can go some way using SQL create table statements including indexes and relationships but this
won't handle all the properties and for your purposes would ultimately be a waste of time.
I would use code which enumerates all properties in DAO (others might use ADOX if that can handle
all the properties). There are a lot of properties which in practice are set by default but it would
be simpler to store them all. Don't forget that some properties cannot be read (trap this error and
ignore them) and that to handle custom properties (which include field descriptions) you will
require the fully extended syntax ...xxx.properties("yyy"). To rebuild you would need to do things
in the right order. (ie tables before foreign keys).

Maybe someone has done this - XML would be a good output notation.

A much easier way would be to have the tables in SQL server or some other db where you can generate
them from a script!

Thanks for the reply, pp

Yes, that's all pretty much what I had in mind. I thought about creating
DDL statements like you say, but wanted to be able to capture all the odd
little jet properties. As I write, though, I realize that there may
substantial advantage in avoiding all the Jet-specific stuff anyways.

I've already written code to synchronize schemas in DAO, so I have an idea
of what's involved on that end. I was wondering if anyone has written the
code to do the text export and then parsing of the text for import.

XML is OK, but also annoyingly verbose for my tastes. I suppose I could
mimic the format of the SaveAsText format, then I'd have something I could
reuse if I ever needed to rebuild a form/report/etc programmatically.


Export table design to text (XML) example is at
http://groups.google.co.uk/group/mic...d5ffafa5abdd30

More googling (or putting in some work!) might find import, and similar code for relations

I agree the DDL route seems better but it depends on the purpose of your backup. The only really
useful things not in (IMHO) are field/table description properties as most of the others are
formatting etc including the lunatic caption property.
Some time ago I wrote something one-off to convert JET to db2 and what follows is modified from
that, without much testing I'm afraid. Include the module in your DB and call the sub
CreateTableQueries. Output DDL is written to a file TEST.TXT and can be pasted into a module in an
empty database and run to recreate the tables of the original database (design only).
One property not captured is if your autonumbers are random.


Hey, excellent, this looks like a great start. I'll make it work for Jet
DDL and post it when I'm done. My current thinking is that this is a good
chance to avoid Jet-specific properties, since it's my intention to make
the app as portable as possible anyways.

Thanks again!
Mar 1 '06 #5
Kevin Chambers <My********@MyName.DontSpamMe.UncleSam> wrote in
news:du*********@enews3.newsguy.com:
Hey, excellent, this looks like a great start. I'll make it work
for Jet DDL and post it when I'm done. My current thinking is
that this is a good chance to avoid Jet-specific properties, since
it's my intention to make the app as portable as possible anyways.


Depending on what metadata you want, keep in mind that certain
Access table properties are going to be completely unknown to DDL,
even Jet's own DDL. So there may be table properties that you can't
get without using DAO. This only matters if your Jet tables were
created with Access and if you're using any of the Access-specific
properties.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Mar 1 '06 #6
David W. Fenton wrote:
Kevin Chambers <My********@MyName.DontSpamMe.UncleSam> wrote in
news:du*********@enews3.newsguy.com:
Hey, excellent, this looks like a great start. I'll make it work
for Jet DDL and post it when I'm done. My current thinking is
that this is a good chance to avoid Jet-specific properties, since
it's my intention to make the app as portable as possible anyways.


Depending on what metadata you want, keep in mind that certain
Access table properties are going to be completely unknown to DDL,
even Jet's own DDL. So there may be table properties that you can't
get without using DAO. This only matters if your Jet tables were
created with Access and if you're using any of the Access-specific
properties.

Thanks for the reminder, David.

For anyone who wants it, here's some code based on pp's previous posting,
refactored to meet my needs.

As DF pointed out, all sorts of properties won't be included in the
generated ddl, default values and validation being the most glaring to me.

Public Function GetTableDdl(mytdef As TableDef) As String
Dim myfld As Field, sql As String
Dim Seperator As String, a As String

sql = "CREATE TABLE " & QuoteObjectName(mytdef.Name) & " ("
Seperator = vbCrLf

For Each myfld In mytdef.Fields
sql = sql & Seperator & " " & QuoteObjectName(myfld.Name) & " "
Select Case myfld.Type
Case dbBoolean 'Boolean
a = "BIT"
Case dbByte 'Byte
a = "BYTE"
Case dbCurrency 'Currency
a = "MONEY"
Case dbDate 'Date / Time
a = "DATETIME"
Case dbDouble 'Double
a = "DOUBLE"
Case dbInteger 'Integer
a = "INTEGER"
Case dbLong 'Long
'test if counter, doesn't detect random property if set
If (myfld.Attributes And dbAutoIncrField) Then
a = "COUNTER"
Else
a = "LONG"
End If
Case dbMemo 'Memo
a = "MEMO"
Case dbSingle 'Single
a = "SINGLE"
Case dbText 'Text
a = "VARCHAR(" & myfld.Size & ")"
Case dbGUID 'Text
a = "GUID"
Case Else
MsgBox "Field " & mytdef.Name & "." & myfld.Name & _
" of type " & myfld.Type & " has been ignored!!!"
End Select
sql = sql & a
If myfld.Required Then
sql = sql & " NOT NULL "
End If
Seperator = ", " & vbCrLf
Next myfld
sql = sql & vbCrLf & ");"
GetTableDdl = sql
End Function

Public Function GetIndexDdl(mytdef As TableDef, myindex As index) As String
Dim sql As String, Seperator As String, myfld As Field

If Left(myindex.Name, 1) = "{" Then
'ignore, GUID-type indexes - bugger them
ElseIf myindex.Foreign Then
'this index was created by a relation. recreating the
'relation will create this for us, so no need to do it here
Else
Seperator = vbCrLf
sql = "CREATE "
If myindex.Unique Then
sql = sql & "UNIQUE "
End If
sql = sql & "INDEX " & QuoteObjectName(myindex.Name) & " ON " & _
QuoteObjectName(mytdef.Name) & "("
For Each myfld In myindex.Fields
sql = sql & Seperator & QuoteObjectName(myfld.Name)
Seperator = ", " & vbCrLf
Next myfld
sql = sql & vbCrLf & ")"
If myindex.primary Then
sql = sql & vbCrLf & " WITH PRIMARY"
ElseIf myindex.IgnoreNulls Then
sql = sql & vbCrLf & " WITH IGNORE NULL"
ElseIf myindex.Required Then
sql = sql & vbCrLf & " WITH DISALLOW NULL"
End If
sql = sql & ";"
End If
GetIndexDdl = sql
End Function

' Returns the SQL DDL to add a relation between two tables.
' Oddly, DAO will not accept the ON DELETE or ON UPDATE
' clauses, so the resulting sql must be executed through ADO
Public Function GetRelationDdl(myrel As Relation) As String
Dim mytdef As TableDef
Dim myfld As Field
Dim sql As String, Seperator As String

With myrel
sql = "ALTER TABLE " & QuoteObjectName(.ForeignTable) & _
" ADD CONSTRAINT " & QuoteObjectName(.Name) & " FOREIGN KEY ("
Seperator = vbCrLf
For Each myfld In .Fields 'ie fields of the relation
sql = sql & Seperator & " " & QuoteObjectName(myfld.ForeignName)
Seperator = "," & vbCrLf
Next
sql = sql & ")" & vbCrLf & "REFERENCES " & _
QuoteObjectName(.Table) & "("
Seperator = vbCrLf
For Each myfld In .Fields
sql = sql & Seperator & " " & QuoteObjectName(myfld.Name)
Seperator = "," & vbCrLf
Next
sql = sql & ")"
If (myrel.Attributes And dbRelationUpdateCascade) Then _
sql = sql & vbCrLf & "ON UPDATE CASCADE"
If (myrel.Attributes And dbRelationDeleteCascade) Then _
sql = sql & vbCrLf & "ON DELETE CASCADE"
sql = sql & ";"
End With
GetRelationDdl = sql
End Function

Private Function QuoteObjectName(Str As String) As String
' Handle metadata object names with spaces, reserved words,
' or other odd stuff.
' Other flavors of sql use quotes for this
QuoteObjectName = "[" & Str & "]"
End Function
Mar 2 '06 #7

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

Similar topics

10
by: bsandell | last post by:
I need to write a stored procedure to verify that a table exists and also that the user executing the stored procedure has access to the specified table. Any user can call this publicly...
2
by: gandalf.me | last post by:
I was just wondering if we can export just the schema/metadata in DB2 (i.e. just the table and column information, without the data). Is there an easy way to do this in DB2? Thanks in advance.
4
by: Dom Hicklin | last post by:
I have created a form onto which images can be dropped and thus added to the OLE field of a Table (Access 2000 linked to SQL 2000 server). I use the Stephen Lebans ExportOLE function to do this...
3
by: Fran Zablocki | last post by:
I have a process that exports an Access table to a comma-delimited text file. One of the fields that is exported shows the date it was exported, using the Date() function. In the Access table, the...
1
by: nunYa | last post by:
I am trying to use the DoCmd.TransferText method to export an access table to a Tab Delimited Text File. I have put the code behind the onclick event of a button and keep getting the error...
7
by: purushneel | last post by:
Hi, I have a following issue in DB2 UDB v8.2. How can I build some data and store it in a temp table and return as a TABLE to a function.. This function will be called in a SELECT stmt....
6
by: sara | last post by:
I have what I think is a little strange...I have to get data from our payroll system into a specific format (fixed record length) as a .txt or .prn file only to upload to our 401k custodian. I...
1
by: Marty Klunk | last post by:
I have an Access97 data base where we are exporting records out to a text file that is then sent to a customer via EDI transmission. The problem I am having is that during the export process access...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.