OK - I updated from Horde Webmail 3 to Horde Webmail 4.
In that transition, the 'horde_prefs' table now shows that the 'pref_value' field is of type BLOB. Previously, it was of type LONGTEXT.
When setting up new accounts, I want to give all of the users default preferences before the user logs in - to ensure that they all have the proper default preferences.
Before, I simply created a PHP script with all of the default values as SQL entries - and inserted them with the username. Now, because these are BLOB entries, I cannot do so.
So in essence, the table has four fields:
pref_uid (the username)
pref_scope (the application that the preference is set for - like horde, ingo, imp, etc)
pref_name (the name of the preference - such as last_login, last_maintenance, etc)
pref_value (the BLOB entry that contains the actual preference)
So - there might be 20+ rows for one user account and all the preferences.
I'd like to copy all of the rows from one user (say tester#test.com) to make the default preferences for the new user (say newuser#test.com)
Is there any way that this can be done?
Thank you!
It is possible like the following:
insert into horde_prefs(pref_uid, pref_scope, pref_name, pref_value)
select 'newuser#test.com', pref_scope, pref_name, pref_value
from horde_prefs
where pref_uid='tester#test.com'
the insert into .. select .. works with blobs too.
Related
In Kingswaysoft's Dynamics 365 Integration Toolkit, is there any way to lookup/match CRM ownerid GUID from source table to a custom column in destination's user entity?
My problem
For some reason, I have to perform a text lookup from source entity's ownerid field to destination user entity's new_legacyuserid custom column that holds user GUIDs from the source system. But it seems like the Text Lookup Editor doesn't match source ownerid with new_legacyuserid column in the destination user entity, but matches if I pass owneridname column as an input.
I have pre populated the new_legacyuserid with a single GUID from the source as a fallback user indication and this column is null for all other records. So all the records' ownerid should fallback to the default user.
Now, when I pass ownerid as an input to the Text Lookup (please see the image below) the package fails with the following error:
{"error":{"code":"0x80040217","message":"systemuser With Id =
be33cd29-671b-e511-80ce-005056ae320c Does Not Exist"}}
However, to test differently, when I pass owneridname as an input to the TextLookup, the package runs successfully and all the two records ownership falls back to the default destination user.
I want to perform the same match using ownerid and not owneridname.
I didn't find any way to use user GUID (OwnerId in this case) in the Text Lookup Editor. It seems that when GUID is passed as an input, the KWS adapter doesn't look at the Text Lookup Editor at all.
One of my colleague tried this workaround and this worked. You can try that if your source CRM is on-premises.
Create a derived column in SQL select statement (OwnerIdString) to
store GUID as a string
Use OwnerIdString column as input
Example:
SELECT task.*, convert(VARCHAR(36), ownerid) AS OwnerIdString FROM task
This will force the Kingswaysoft adapter to do a Text Lookup based on GUID.
I'm working on a project where users could upload excel files into a MySQL database. Those files are the main source of our data as they come directly from the contractors working with the company. They contain a large number of rows (23000 on average for each file) and 100 columns for each row!
The problem I am facing currently is that the same file could be changed by someone (either the contractor or the company) and when re-uploading it, my system should detect changes, update the actual data, and save the action (The fact that the cell went from a value to another value :: oldValue -> newValue) so we can go back and run a versions comparison (e.g 3 re-uploads === 3 versions). (oldValue Version1 VS newValue Version5)
I developed a tiny mechanism for saving the changes => I have a table to save Imports data (each time a user import a file a new row will be inserted in this table) and another table for saving the actual changes
Versioning data
I save the id of the row that have some changes, as well as the id and the table where the actual data was modified (Uploading a file results in a insertion in multiple tables, so whenever a change occurs, I need to know in which table that happened). I also save the new value and the old value which is gonna help me with restoring the "archives data".
To restore a version : SELECT * FROM 'Archive' WHERE idImport = ${versionNumber}
To restore a version for one row : SELECT * FROM 'Archive' WHERE idImport = ${versionNumber} and rowId = ${rowId}
To restore all version for one row : SELECT * FROM 'Archive' WHERE rowId = ${rowId}
To restore version for one table : SELECT * FROM 'Archine' WHERE tableName = ${table}
Etc.
Now with this structure, I'm struggling to restore a version or to run a comparaison between two versions, which makes think that I've came up with a wrong approach since it makes it hard to do the job! I am trying to know if anyone had done this before or what a good approach would look like?
Cases when things get really messy :
The rows that have changed in a version might not have changed in the other version (I am working on a time machine to search in other versions when this happens)
The rows have changed in both versions but not the same fields. (Say we have a user table, the data of the user with id 15 have changed in 2nd and 5th upload, great! Now for the second version only the name was changed, but for the fifth version his address was changed! When comparing these two versions, we will run into a problem constrcuting our data array. name went from "some"-> NULL (Name was never null. No name changes in 5th version) and address went from NULL -> "some' is which obviously wrong).
My actual approach (php)
<?php
//Join records sets and Compare them
foreach ($firstRecord as $frecord) {
//Retrieve first record fields that have changed
$fFields = $frecord->fieldName;
//Check if the same record have changed in the second version as well
$sId = array_search($frecord->idRecord, $secondRecord);
if($sId) {
$srecord = $secondRecord[$sId];
//Retrieve straversee fields that have changed
$sFields = $srecord->fieldName;
//Compare the two records fields
foreach ($fFields as $fField) {
$sfId = array_search($fField, $sFields);
//The same field for the same record was changed in both version (perfect case)
if($sfId) {
$sField = $sFields[$sfId];
$deltaRow[$fField]["oldValue"] = $frecord->deltaValue;
$deltaRow[$fField]["newValue"] = $srecord->deltaValue;
//Delete the checked field from the second version traversee to avoid re-checking
unset($sField[$sfId]);
}
//The changed field in V1 was not found in V2 -> Lookup for a value
else {
$deltaRow[$fField]["oldValue"] = $frecord->deltaValue;
$deltaRow[$fField]["newValue"] = $this->valueLookUp();
}
}
$dataArray[] = $deltaRow;
//Delete the checked record from the second version set to avoid re-checking
unset($secondRecord[$srecord]);
}
I don't know how to deal with that, as I said I m working on a value lookup algorithm so when no data found in a version I will try to find it in the versions between theses two so I can construct my data array. I would be very happy if anyone could give some hints, ideas, improvements so I can go futher with that.
Thank you!
Is there a way to store database modifications with a versioning feature (for eventual versions comparaison [sic!])?
What constitutes versioning depends on the database itself and how you make use of it.
As far as a relational database is concerned (e.g. MariaDB), this boils down to the so called Normal Form which is in numbers.
On Database Normalization: 5th Normal Form and Beyond you can find the following guidance:
Beyond 5th normal form you enter the heady realms of domain key normal form, a kind of theoretical ideal. Its practical use to a database designer os [sic!] similar to that of infinity to a bookkeeper - i.e. it exists in theory but is not going to be used in practice. Even the most demanding owner is not going to expect that of the bookkeeper!
One strategy to step into these realms is to reach the 5th normal form first (do this just in theory, by going through all the normal forms, and study database normalization).
Additionally you can construe versioning outside and additional to the database itself, e.g. by creating your own versioning system. Reading about what you can do with normalization will help you to find better ways to decide on how to structure and handle the database data for your versioning needs.
However, as written it depends on what you want and need. So no straight forward "code" answer can be given to such a general question.
I have recently started managing an Access DB used for reporting. Currently a single row has a 'status' that can be one of many options selected by a dropdown field. When reporting, each of these ~15 statuses rolls up to one of 5 'rollup statuses' which is currently translated via an Excel interface. I would like to add a column to the database table that automatically populates the correct 'rollup status' based on the selected 'status'. I do not know if this is a calculated field, a lookup, etc. as I have very minimal Access knowledge.
For example:
[Status]---->[Rollup Status]
To Be Scheduled----> Planning
TBD---->Planning
Scheduled---->Scheduled
DMM Pending---->Scheduled
EEP Created---->Scheduled
Cleanup Pending---->Complete
Complete---->Complete
If i understand your question correctly perhaps this would work...
In design mode: Add the new column to your table (which i will call 'total') where you want the 'rollup statuses' and call it something like 'rollup_status'
In SQL Query mode:
UPDATE total
SET rollup_status = '1'
WHERE [status] = '2';
I have a database with a lot of entries for images that I want to rename. Let's say all the images have the name Something_X where X is a number, this is in a column called "name" of my database. There are 2 columns in the database that have the original filesize called "original_width" and "original_height". I want to change all the entries in "name" that it still has the original but it adds the original size to it so that "Something_X" becomes "Something_X_widthxheight", is this possible and how would I do this with PHP my admin in a simple way with preferably a SQL code.
UPDATE <yourTableName>
SET name = CONCAT(name,'_',original_width,'x',original_height);
To update only rows that haven't been updated, you can use the below (sqlFiddle)
UPDATE yourTable
SET name = CONCAT(name,'_',original_width,'x',original_height)
WHERE name NOT LIKE CONCAT('%\_',original_width,'x',original_height);
Basically I want to query a database and modify the values of one column based on the contents of another.
Here's my idea of how it would work:
IF Column 'Town' IS NOT NULL then Column 'Sign-up type' = 1 else = 0
The logic is, i've added a new column into the DB that will store whether a quick or full sign up has been made.
Quick = 0, Full = 1. Default is 0 = Quick.
I've managed to implement the change on the two registration forms that feed the DB, but I need to append the historical data to backwards fill the data.
Because the quick sign up only collects name, and email, those entries do not contain data in the 'Town' field which is a required field in a full sign up.
So i'm using that as a reference point to select all the entries that DO have (NOT NULL?) data in order to enter '1' (representing 'Full') into 'Signup Type' column.
I hope I'm making sense! I only have a basic understanding of MySQL but I'm willing to learn, it's sometimes hard trying to explain what I want to do when I'm unclear of the correct jargon!!
UPDATE yourTable SET signupType = IF(Town IS NULL, 1, 0);
Note this will update all data, you may want to limit this to historical data (by the sounds of things this should be fine however).