Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
ab17fd19
Commit
ab17fd19
authored
Apr 03, 2001
by
Philip Warner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Handle overridden attrs as per discussions 2-Apr-2001
- Dump CHECK constraints in OID order
parent
08bf4d79
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
126 additions
and
26 deletions
+126
-26
src/bin/pg_dump/common.c
src/bin/pg_dump/common.c
+107
-19
src/bin/pg_dump/pg_backup_archiver.h
src/bin/pg_dump/pg_backup_archiver.h
+2
-2
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dump.c
+14
-4
src/bin/pg_dump/pg_dump.h
src/bin/pg_dump/pg_dump.h
+3
-1
No files found.
src/bin/pg_dump/common.c
View file @
ab17fd19
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.5
4 2001/03/22 04:00:11 momjian
Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.5
5 2001/04/03 08:52:59 pjw
Exp $
*
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
*
...
...
@@ -21,6 +21,10 @@
* string to return - formatted type, or base type. If the base type
* is returned then fmtId is called on the string.
*
* Modifications 4-Apr-2001 - pjw@rhyme.com.au
* - Changed flagInhAttrs to check all parent tables for overridden settings
* and set flags accordingly.
*
* BEWARE: Since fmtId uses a static buffer, using 'useBaseTypeName' on more
* than one call in a line will cause problems.
*
...
...
@@ -39,7 +43,8 @@
static
char
**
findParentsByOid
(
TableInfo
*
tbinfo
,
int
numTables
,
InhInfo
*
inhinfo
,
int
numInherits
,
const
char
*
oid
,
int
*
numParents
);
int
*
numParents
,
int
(
**
parentIndices
)[]);
static
int
findTableByOid
(
TableInfo
*
tbinfo
,
int
numTables
,
const
char
*
oid
);
static
void
flagInhAttrs
(
TableInfo
*
tbinfo
,
int
numTables
,
InhInfo
*
inhinfo
,
int
numInherits
);
...
...
@@ -122,7 +127,7 @@ findOprByOid(OprInfo *oprinfo, int numOprs, const char *oid)
/*
* findParentsByOid
* given the oid of a class, return the names of its parent classes
* and assign the number of parents
to the last argument
.
* and assign the number of parents
, and parent indices to the last arguments
.
*
*
* returns NULL if none
...
...
@@ -131,7 +136,7 @@ findOprByOid(OprInfo *oprinfo, int numOprs, const char *oid)
static
char
**
findParentsByOid
(
TableInfo
*
tblinfo
,
int
numTables
,
InhInfo
*
inhinfo
,
int
numInherits
,
const
char
*
oid
,
int
*
numParentsPtr
)
int
*
numParentsPtr
,
int
(
**
parentIndices
)[]
)
{
int
i
,
j
;
...
...
@@ -152,6 +157,7 @@ findParentsByOid(TableInfo *tblinfo, int numTables,
if
(
numParents
>
0
)
{
result
=
(
char
**
)
malloc
(
sizeof
(
char
*
)
*
numParents
);
(
*
parentIndices
)
=
malloc
(
sizeof
(
int
)
*
numParents
);
j
=
0
;
for
(
i
=
0
;
i
<
numInherits
;
i
++
)
{
...
...
@@ -169,13 +175,17 @@ findParentsByOid(TableInfo *tblinfo, int numTables,
oid
);
exit
(
2
);
}
(
**
parentIndices
)[
j
]
=
parentInd
;
result
[
j
++
]
=
tblinfo
[
parentInd
].
relname
;
}
}
return
result
;
}
else
{
(
*
parentIndices
)
=
NULL
;
return
NULL
;
}
}
/*
...
...
@@ -415,6 +425,14 @@ flagInhAttrs(TableInfo *tblinfo, int numTables,
j
,
k
;
int
parentInd
;
int
inhAttrInd
;
int
(
*
parentIndices
)[];
bool
foundAttr
;
/* Attr was found in a parent */
bool
foundNotNull
;
/* Attr was NOT NULL in a parent */
bool
defaultsMatch
;
/* All non-empty defaults match */
bool
defaultsFound
;
/* Found a default in a parent */
char
*
attrDef
;
char
*
inhDef
;
/*
* we go backwards because the tables in tblinfo are in OID order,
...
...
@@ -423,27 +441,97 @@ flagInhAttrs(TableInfo *tblinfo, int numTables,
*/
for
(
i
=
numTables
-
1
;
i
>=
0
;
i
--
)
{
/* Sequences can never have parents, and attr info is undefined */
if
(
tblinfo
[
i
].
sequence
)
continue
;
/* Get all the parents and their indexes. */
tblinfo
[
i
].
parentRels
=
findParentsByOid
(
tblinfo
,
numTables
,
inhinfo
,
numInherits
,
tblinfo
[
i
].
oid
,
&
tblinfo
[
i
].
numParents
);
for
(
k
=
0
;
k
<
tblinfo
[
i
].
numParents
;
k
++
)
&
tblinfo
[
i
].
numParents
,
&
parentIndices
);
/*
* For each attr, check the parent info: if no parent has
* an attr with the same name, then it's not inherited. If there
* *is* an attr with the same name, then only dump it if:
*
* - it is NOT NULL and zero parents are NOT NULL
* OR
* - it has a default value AND the default value
* does not match all parent default values, or
* no parents specify a default.
*
* See discussion on -hackers around 2-Apr-2001.
*/
for
(
j
=
0
;
j
<
tblinfo
[
i
].
numatts
;
j
++
)
{
parentInd
=
findTableByName
(
tblinfo
,
numTables
,
tblinfo
[
i
].
parentRels
[
k
]);
if
(
parentInd
<
0
)
foundAttr
=
false
;
foundNotNull
=
false
;
defaultsMatch
=
true
;
defaultsFound
=
false
;
attrDef
=
tblinfo
[
i
].
adef_expr
[
j
];
for
(
k
=
0
;
k
<
tblinfo
[
i
].
numParents
;
k
++
)
{
/* shouldn't happen unless findParentsByOid is broken */
fprintf
(
stderr
,
"failed sanity check, table %s not found by flagInhAttrs
\n
"
,
tblinfo
[
i
].
parentRels
[
k
]);
exit
(
2
);
}
for
(
j
=
0
;
j
<
tblinfo
[
i
].
numatts
;
j
++
)
parentInd
=
(
*
parentIndices
)[
k
];
if
(
parentInd
<
0
)
{
/* shouldn't happen unless findParentsByOid is broken */
fprintf
(
stderr
,
"failed sanity check, table %s not found by flagInhAttrs
\n
"
,
tblinfo
[
i
].
parentRels
[
k
]);
exit
(
2
);
};
inhAttrInd
=
strInArray
(
tblinfo
[
i
].
attnames
[
j
],
tblinfo
[
parentInd
].
attnames
,
tblinfo
[
parentInd
].
numatts
);
if
(
inhAttrInd
!=
-
1
)
{
foundAttr
=
true
;
foundNotNull
|=
tblinfo
[
parentInd
].
notnull
[
inhAttrInd
];
if
(
attrDef
!=
NULL
)
/* It we have a default, check parent */
{
inhDef
=
tblinfo
[
parentInd
].
adef_expr
[
inhAttrInd
];
if
(
inhDef
!=
NULL
)
{
defaultsFound
=
true
;
defaultsMatch
&=
(
strcmp
(
attrDef
,
inhDef
)
==
0
);
};
};
};
};
/*
* Based on the scan of the parents, decide if we
* can rely on the inherited attr
*/
if
(
foundAttr
)
/* Attr was inherited */
{
if
(
strInArray
(
tblinfo
[
i
].
attnames
[
j
],
tblinfo
[
parentInd
].
attnames
,
tblinfo
[
parentInd
].
numatts
)
!=
-
1
)
tblinfo
[
i
].
inhAttrs
[
j
]
=
1
;
/* Set inherited flag by default */
tblinfo
[
i
].
inhAttrs
[
j
]
=
1
;
tblinfo
[
i
].
inhAttrDef
[
j
]
=
1
;
tblinfo
[
i
].
inhNotNull
[
j
]
=
1
;
/* Clear it if attr had a default, but parents did not, or mismatch */
if
(
(
attrDef
!=
NULL
)
&&
(
!
defaultsFound
||
!
defaultsMatch
)
)
{
tblinfo
[
i
].
inhAttrs
[
j
]
=
0
;
tblinfo
[
i
].
inhAttrDef
[
j
]
=
0
;
}
/* Clear it if NOT NULL and none of the parents were NOT NULL */
if
(
tblinfo
[
i
].
notnull
[
j
]
&&
!
foundNotNull
)
{
tblinfo
[
i
].
inhAttrs
[
j
]
=
0
;
tblinfo
[
i
].
inhNotNull
[
j
]
=
0
;
}
}
}
}
...
...
src/bin/pg_dump/pg_backup_archiver.h
View file @
ab17fd19
...
...
@@ -17,7 +17,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.2
8 2001/04/01 05:42:51
pjw Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.2
9 2001/04/03 08:52:59
pjw Exp $
*
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
* - Initial version.
...
...
@@ -68,7 +68,7 @@ typedef z_stream *z_streamp;
#define K_VERS_MAJOR 1
#define K_VERS_MINOR 5
#define K_VERS_REV
0
#define K_VERS_REV
1
/* Data block types */
#define BLK_DATA 1
...
...
src/bin/pg_dump/pg_dump.c
View file @
ab17fd19
...
...
@@ -22,7 +22,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.19
8 2001/04/01 05:42:51
pjw Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.19
9 2001/04/03 08:52:59
pjw Exp $
*
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
*
...
...
@@ -1603,6 +1603,10 @@ clearTableInfo(TableInfo *tblinfo, int numTables)
free
((
int
*
)
tblinfo
[
i
].
atttypmod
);
if
(
tblinfo
[
i
].
inhAttrs
)
free
((
int
*
)
tblinfo
[
i
].
inhAttrs
);
if
(
tblinfo
[
i
].
inhAttrDef
)
free
((
int
*
)
tblinfo
[
i
].
inhAttrDef
);
if
(
tblinfo
[
i
].
inhNotNull
)
free
((
int
*
)
tblinfo
[
i
].
inhNotNull
);
if
(
tblinfo
[
i
].
attnames
)
free
(
tblinfo
[
i
].
attnames
);
if
(
tblinfo
[
i
].
atttypedefns
)
...
...
@@ -2138,7 +2142,8 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
" where i.inhrelid = pg_relcheck.rcrelid "
" and c.rcname = pg_relcheck.rcname "
" and c.rcsrc = pg_relcheck.rcsrc "
" and c.rcrelid = i.inhparent) "
,
" and c.rcrelid = i.inhparent) "
" Order By oid "
,
tblinfo
[
i
].
oid
);
res2
=
PQexec
(
g_conn
,
query
->
data
);
if
(
!
res2
||
...
...
@@ -2656,6 +2661,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
tblinfo
[
i
].
typnames
=
(
char
**
)
malloc
(
ntups
*
sizeof
(
char
*
));
tblinfo
[
i
].
atttypmod
=
(
int
*
)
malloc
(
ntups
*
sizeof
(
int
));
tblinfo
[
i
].
inhAttrs
=
(
int
*
)
malloc
(
ntups
*
sizeof
(
int
));
tblinfo
[
i
].
inhAttrDef
=
(
int
*
)
malloc
(
ntups
*
sizeof
(
int
));
tblinfo
[
i
].
inhNotNull
=
(
int
*
)
malloc
(
ntups
*
sizeof
(
int
));
tblinfo
[
i
].
notnull
=
(
bool
*
)
malloc
(
ntups
*
sizeof
(
bool
));
tblinfo
[
i
].
adef_expr
=
(
char
**
)
malloc
(
ntups
*
sizeof
(
char
*
));
tblinfo
[
i
].
parentRels
=
NULL
;
...
...
@@ -2678,6 +2685,9 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
tblinfo
[
i
].
atttypmod
[
j
]
=
atoi
(
PQgetvalue
(
res
,
j
,
i_atttypmod
));
tblinfo
[
i
].
inhAttrs
[
j
]
=
0
;
/* this flag is set in
* flagInhAttrs() */
tblinfo
[
i
].
inhAttrDef
[
j
]
=
0
;
tblinfo
[
i
].
inhNotNull
[
j
]
=
0
;
tblinfo
[
i
].
notnull
[
j
]
=
(
PQgetvalue
(
res
,
j
,
i_attnotnull
)[
0
]
==
't'
)
?
true
:
false
;
if
(
PQgetvalue
(
res
,
j
,
i_atthasdef
)[
0
]
==
't'
)
{
...
...
@@ -3829,12 +3839,12 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
tblinfo
[
i
].
atttypedefns
[
j
]);
/* Default value */
if
(
tblinfo
[
i
].
adef_expr
[
j
]
!=
NULL
)
if
(
tblinfo
[
i
].
adef_expr
[
j
]
!=
NULL
&&
tblinfo
[
i
].
inhAttrDef
[
j
]
==
0
)
appendPQExpBuffer
(
q
,
" DEFAULT %s"
,
tblinfo
[
i
].
adef_expr
[
j
]);
/* Not Null constraint */
if
(
tblinfo
[
i
].
notnull
[
j
])
if
(
tblinfo
[
i
].
notnull
[
j
]
&&
tblinfo
[
i
].
inhNotNull
[
j
]
==
0
)
appendPQExpBuffer
(
q
,
" NOT NULL"
);
actual_atts
++
;
...
...
src/bin/pg_dump/pg_dump.h
View file @
ab17fd19
...
...
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_dump.h,v 1.6
0 2001/03/23 04:49:56 momjian
Exp $
* $Id: pg_dump.h,v 1.6
1 2001/04/03 08:52:59 pjw
Exp $
*
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
*
...
...
@@ -93,6 +93,8 @@ typedef struct _tableInfo
int
*
inhAttrs
;
/* an array of flags, one for each
* attribute if the value is 1, then this
* attribute is an inherited attribute */
int
*
inhAttrDef
;
/* Flags indicating if attrdef is inherited */
int
*
inhNotNull
;
/* Flags indicating if NOT NULL in inherited */
char
**
attnames
;
/* the attribute names */
char
**
attoids
;
/* oids of the various attributes */
char
**
atttypedefns
;
/* formatted column type definitions */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment