I have a table 'EMPLOYEES' where the users have an incorrect email address.
I need to update the email address using 3 service providers like gmail, yahoo, outlook. I have a large number of records so I can't do it one by one.
How can I write that query to update them all at once.?
In the email column, each record must have a valid email address
The first record in my table in the email field is sking. After update it should become jusking#yahoo.com it should only take one domain not all 3 together.
The second record should be nkochhar#gmail.com
The third party ledhaan#yahoo.com
And so it should be with each record, one of the three domains must be added to make it a valid email address.
sking#gmail.com
nkochhar#yahoo.com
ldehaan#outlook.com
name4#yahoo.com
name5#outlook.com
name6#yahoo.com
name7#yahoo.com
name8#outlook.com
name#gmail.com
name#gmail.com
...
I found this on Google but I don't know how to apply it to what I need:
for (int i = 0; i <rowsCount; i ++) {
cv.put (column2, columnValue [1]);
cv.put (column3, columnValue [1]);
db.update (tableName, cv, null, null);
}
I tried to do this but it shows an error:
I need help please, I'm a beginner at this :(
To update email field randomly with #outlook.com, #yahoo.com or #gmail.com use below query:
update employees
set email= (case when mod(employee_id,3)=0 then concat(email,'#outlook.com') when mod(employee_id ,2)=1 then concat(email,'#yahoo.com') else concat(email, '#gmail.com') end);
In both MySql and Oracle database this query will work fine.
Related
Can we use :xdo_user_name for filter logic with WebLogic?
I created a datamodel in oracle BI Publisher,with where clause like below:
WHERE (EMPLOYEE_NO = :xdo_user_name)
which works normally if I login with an employee account.
But I would like to make it show all data when I login as 'weblogic',so I changed it to:
WHERE (EMPLOYEE_NO = :xdo_user_name
OR (CASE WHEN :xdo_user_name = 'weblogic' THEN 1=1 END))
Error is shown:
Character dat, right truncation occurred:for example, an update or insert value is a string that is too long for the column, or a datetime value cannot be assigned to a host variable, because it is too small.
Not so sure about why this error show up. Please advise.
Try it like this...
WHERE EMPLOYEE = CASE WHEN :xdo_user_name = 'weblogic' THEN EMPLOYEE ELSE :xdo_user_name END
this way, when logged in as 'weblogic', where condition will return True for every row - otherwise it will be True just for rows where EMPLOYEE = :xdo_user_name.
Regards...
I want to get the next id that will be created but not yet in laravel.
Is this code correct?
$tableStatus = DB::select("show table status from database_name where Name = 'table_name'");
if (empty($tableStatus)) {
throw new \Exception("Table not found");
}
// Get first table result, get its next auto incrementing value
echo $tableStatus[0]->Auto_increment;
Yes, the code is correct.
You can achive this in several other ways. For example, You can query the particular database table to extract last created id by ordering the rows based on created_at column or id column itself and finally increment the value by 1 to get next auto-increment value.
For every request I found that 4 queries are fired to validate the user and the token. Among them one is to fetch the user (select * from user) based on the user id. This queries are fired by Passport/Laravel But what I want is to modify this query to add one status field check also to check if any user become invalid during the token validity period. If we only check with the id then if any user become inactive(By changing status then also we will not be able to stop the user as deleting the token for the user is not a good solution for me).
Queries Fired on every request by Passport Laravel:
select * from oauth_access_tokens where id = ?
select * from user where id = ? limit 1 ["2"]
select * from oauth_access_tokens where id = ?
select * from oauth_clients where id = ?
So, can anyone tell me how to change the 'select * from user where id' query in passport at time of Token validation.
You can add this method on your User model (or any model you're authenticating with passport)
...
public function findForPassport($username)
{
return $user = (new self)->where('email', $username)->where('is_active', 1)->first();
}
...
of course you can modify is_active by whichever column you are using (and/or any query constraint for that matter), as long as it returns Illuminate\Contracts\Auth\Authenticatable contract.
I wouldn't try and modify passports default behaviour as I have no idea what else it might impact both now and in future upgrades.
Your best bet might be to hook into the passport events and apply you business logic to a listener that is called when the events are fired
In the following code, The Users table has a related table phoneNumbers. When I retrieve a list of all users like this,
return Person::with('phoneNumbers')->get();
everything works fine. However, when I attempt to specify a list of columns to return from the Person table, the phone_number returns empty.
return Person::with('phoneNumbers')
->get(['fname','lname', 'email']);
If I add the number field or phone_number.number to the get array, then I get an error as an undefined column. What is the laravel way of handling this.
Try this:
return Person::select(['your_foreign_key', 'fname','lname', 'email'])
->with('phoneNumbers')get();
I am way to customizing 'Sales' application that belongs to 'salesforce.com' platform.
Is there any way to select all the 'OpportunityProducts' objects which are belongs to particular 'Opportunity Id' ?
[SELECT Id FROM OpportunityProduct WHERE Opportunity =:opportunitId];
When I execute above code for select those 'OpportunityProduct', I got following error. If any one have some idea please update me. Thanks.
Save error: sObject type 'OpportunityProduct' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.
Another way to get this done when you need the actual products, not just the line items, is as follows. First get your opportunities:
List<Opportunity> opps = [SELECT Id, Name FROM Opportunity LIMIT 1000];
Then loop through to create a list of opportunity Ids
List<Id> oppIds = new List<Id>();
for(Opportunity o : opps)
{
oppIds.add(o.Id);
}
Now get your actual products that belong to your opportunities...
List<OpportunityLineItem> oppProds = [SELECT Id, PricebookEntry.Product2.Name, PricebookEntry.Product2.Family
FROM OpportunityLineItem
WHERE OpportunityId IN :oppIds];
Hope that helps.