Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
redmine-sync
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gerhard Gonter
redmine-sync
Commits
aa00521d
Commit
aa00521d
authored
9 months ago
by
Gerhard Gonter
Browse files
Options
Downloads
Patches
Plain Diff
allow other columns than "id" to be the primary key which is used for caching
parent
98215c5d
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/Redmine/DB/MySQL.pm
+31
-7
31 additions, 7 deletions
lib/Redmine/DB/MySQL.pm
with
31 additions
and
7 deletions
lib/Redmine/DB/MySQL.pm
+
31
−
7
View file @
aa00521d
...
...
@@ -31,7 +31,8 @@ sub connect
# print "db_con=[$db_con]\n";
$dbh
=
DBI
->
connect
(
$db_con
,
map
{
$self
->
{
$_
}
}
qw(username password)
);
# print "dbh=[$dbh]\n";
print
join
('
',
__FILE__
,
__LINE__
,
'
caller
',
caller
(),
"
dbh=[
$dbh
]
\n
");
# exit;
if
(
exists
(
$self
->
{
encoding
}))
{
...
...
@@ -110,14 +111,14 @@ sub get_all_x
my
$t
=
$self
->
table
(
$table
);
my
$tt
=
{};
my
$pri
=
(
exists
(
$self
->
{
PRI
}
->
{
$table
}))
?
$self
->
{
PRI
}
->
{
$table
}
:
'
id
';
my
$pri
=
(
exists
(
$self
->
{
PRI
}
->
{
$table
}))
?
$self
->
{
PRI
}
->
{
$table
}
:
[
'
id
'
]
;
# print __LINE__, " pri=[$pri] ", main::Dumper ($self->{PRI});
# print __LINE__, " pri=[$pri]\n";
# print __LINE__, "
table=[$table]
pri=[$pri]\n";
while
(
defined
(
my
$x
=
$sth
->
fetchrow_hashref
()))
{
print
"
x:
",
Dumper
(
$x
)
if
(
$show_fetched
);
my
$i
=
$x
->
{
$pri
}
;
my
$i
=
join
('
,
',
map
{
$x
->
{
$_
}
}
@
$pri
)
;
$t
->
{
$i
}
=
$tt
->
{
$i
}
=
$x
;
}
...
...
@@ -224,6 +225,7 @@ sub desc
# my @desc_columns= qw(Field Type Null Key Default Extra);
my
@PRI
;
while
(
my
@x
=
$sth
->
fetchrow_array
())
{
last
unless
(
@x
);
...
...
@@ -232,10 +234,14 @@ sub desc
if
(
$x
[
3
]
eq
'
PRI
')
{
$self
->
{
PRI
}
->
{
$table
}
=
$x
[
0
];
push
(
@PRI
,
$x
[
0
]
)
;
}
}
my
$PRI
=
join
('
,
',
@PRI
);
$self
->
{
PRI
}
->
{
$table
}
=
\
@PRI
;
# print join(' ', __FILE__, __LINE__, 'table:', $table, 'PRI:', $PRI), "\n";
$td
;
}
...
...
@@ -299,13 +305,31 @@ sub update
push
(
@vars
,
$an
);
push
(
@vals
,
$updates
->
{
$an
});
}
push
(
@vals
,
$id
);
my
$pri
=
(
exists
(
$self
->
{
PRI
}
->
{
$table
}))
?
$self
->
{
PRI
}
->
{
$table
}
:
'
id
';
# print __LINE__, " pri=[$pri] ", main::Dumper ($self->{PRI});
# print __LINE__, " pri=[$pri]\n";
my
$ssu
=
"
UPDATE `
$table
` SET
"
.
join
('
,
',
map
{
$_
.
'
=?
'
}
@vars
)
.
"
WHERE `
$pri
`=?
";
# Hmm... WHERE ?=?
# ATTN: $pri is a array ref with the column names forming the primary key; there can be more than one!!
# TODO: currently only the first variable name is used with a value!
print
__LINE__
,
"
caller:
",
join
('
',
caller
()),
"
\n
";
my
@conditions
;
if
(
ref
(
$pri
)
eq
'
ARRAY
')
{
foreach
my
$attr_name
(
@$pri
)
{
push
(
@conditions
,
"
`
$attr_name
`=?
");
}
push
(
@vals
,
@$id
);
}
else
{
push
(
@conditions
,
"
`
$pri
`=?
");
push
(
@vals
,
$id
);
}
my
$ssu
=
"
UPDATE `
$table
` SET
"
.
join
('
,
',
map
{
$_
.
'
=?
'
}
@vars
)
.
"
WHERE
"
.
join
('
AND
',
@conditions
);
# Hmm... WHERE ?=?
if
(
$show_updates
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment