Why am I getting the following error?
ErrorException in AdsController.php line 69:
Argument 2 passed to App\Http\Controllers\AdsController::pick_campaign() must be an instance of App\Websites, null given, called in /home/getad/dashboard.getad.ir/app/Http/Controllers/AdsController.php on line 256 and defined
line 69:
'protected function pick\_campaign(IlluminateHttpRequest $request, AppWebsites $website, $campaign\_tbl, $params = array( ))'
line 256:
' $eligible = $this->pick\_campaign($request, NULL, $campaign\_tbl, $p);'
Error 2
'QueryException in Connection.php line 631:
SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'details' at row 1 (SQL: insert into transactions (user, type, amount, details, date) values (1, click, 8, a:1:{s:5:"click";O:10:"AppClicks":22:{s:8:"_table";s:6:"clicks";s:10:"timestamps";b:0;s:11:"_fillable";a:9:{i:0;s:5:"token";i:1;s:8:"campaign";i:2;s:6:"banner";i:3;s:7:"website";i:4;s:2:"ip";i:5;s:4:"date";i:6;s:4:"fake";i:7;s:2:"os";i:8;s:7:"browser";}s:13:"_connection";N;s:13:"_primaryKey";s:2:"id";s:10:"_perPage";i:15;s:12:"incrementing";b:1;s:13:"_attributes";a:10:{s:5:"token";i:814927090;s:6:"banner";N;s:8:"campaign";s:2:"13";s:7:"website";s:2:"20";s:2:"ip";s:15:"109.125.175.129";s:4:"date";O:8:"DateTime":3:{s:4:"date";s:26:"2019-06-02 15:12:32.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:11:"Asia/Tehran";}s:4:"fake";i:0;s:2:"os";s:7:"Windows";s:7:"browser";s:6:"Safari";s:2:"id";i:2464;}s:11:"_original";a:10:{s:5:"token";i:814927090;s:6:"banner";N;s:8:"campaign";s:2:"13";s:7:"website";s:2:"20";s:2:"ip";s:15:"109.125.175.129";s:4:"date";r:25;s:4:"fake";i:0;s:2:"os";s:7:"Windows";s:7:"browser";s:6:"Safari";s:2:"id";i:2464;}s:12:"_relations";a:0:{}s:9:"_hidden";a:0:{}s:10:"_visible";a:0:{}s:10:"_appends";a:0:{}s:10:"guarded";a:1:{i:0;s:1:"";}s:8:"_dates";a:0:{}s:13:"_dateFormat";N;s:8:"_casts";a:0:{}s:10:"_touches";a:0:{}s:14:"_observables";a:0:{}s:7:"_with";a:0:{}s:13:"_morphClass";N;s:6:"exists";b:1;}}, 2019-06-02 15:12:32))'
Related
I am getting an error "Error in executeUpdate, Table has no partition for value from column_list"
I have not used SQL in years.
This is the insert
INSERT INTO messages
(RunId, RunStart, RunFinish, ChannelId, StartMessageId,
FinishMessageId, Status, Error, NoOfMessages, NoOfFinalMessages,
NoOfMediaFiles, NoOfNewChannels)
VALUES ('635c8dd3-f476-49a1-8993-570dccb914e9', '2021-11-15 10:43:08.193',
'2021-11-15 10:43:08.211', 1, 1, 100, 'Success', null, 100, 50, 25, 5)
Reading the error, I think its treating one of the params as a list, am I right.
I have not seen this error before, I tried inserting these to my database table
INSERT courses
SET startTime= '30-Dec-2020 09:00:00', exam_catID = 2, courseTitle = 'Test course',
courseCode = 'Tcs299', duration = 3
courses Atributes
startTime (Varchar)
exam_catID (Int)
courseTitle (Varchar)
courseCode (Varchar)
duration (int)
Outpur Error
Fatal error: Uncaught TypeError: Argument 1 passed to PhpMyAdmin\DatabaseInterface::escapeString() must be of the type string, null given, called in C:\xampp\phpMyAdmin\libraries\classes\Tracker.php on line 149 and defined in C:\xampp\phpMyAdmin\libraries\classes\DatabaseInterface.php:2991 Stack trace: #0 C:\xampp\phpMyAdmin\libraries\classes\Tracker.php(149): PhpMyAdmin\DatabaseInterface->escapeString(NULL) #1 C:\xampp\phpMyAdmin\libraries\classes\Tracker.php(841): PhpMyAdmin\Tracker::isTracked('time_table_syst...', NULL) #2 C:\xampp\phpMyAdmin\libraries\classes\DatabaseInterface.php(345): PhpMyAdmin\Tracker::handleQuery('INSERT courses ...') #3 C:\xampp\phpMyAdmin\libraries\classes\Sql.php(958): PhpMyAdmin\DatabaseInterface->tryQuery('INSERT courses ...', 256, 1) #4 C:\xampp\phpMyAdmin\libraries\classes\Sql.php(1177): PhpMyAdmin\Sql->executeQueryAndMeasureTime('INSERT courses ...') #5 C:\xampp\phpMyAdmin\libraries\classes\Sql.php(2225): PhpMyAdmin\Sql->executeTheQuery(Array, 'INSERT courses ...', false, 'time_table_syst in C:\xampp\phpMyAdmin\libraries\classes\DatabaseInterface.php on line 2991
You should use proper insert statement. You are missing INTO clause:
INSERT into courses
SET startTime= '30-Dec-2020 09:00:00', exam_catID = 2, courseTitle = 'Test course',
courseCode = 'Tcs299', duration = 3
Or you can use the standard sql as follows:
INSERT into courses( startTime, exam_catID , courseTitle, courseCode, duration)
values ( '30-Dec-2020 09:00:00', 2, 'Test course', 'Tcs299', 3)
I need to make a query which would be able to delete multiple rows from my table. In order to do that I've created an arrays within array with values which need to be passed to that query. Here is my code:
var deleteRooms = [ [ 3, 23 ], [ 4, 23 ], [ 5, 23 ], [ 2, 23 ]];
connection.query("DELETE FROM rate_plans_rooms WHERE room_id = ? AND rate_plan_id = ? ",
[deleteRooms],function(err,results){
if(err){return console.log(err)}
else
{
console.log('sended');
}
});
But every time I receive an error like this:
{ Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check
the manual that corresponds to your MariaDB server version for the
right syntax to use near ' (4, 23), (5, 23), (2, 23) AND rate_plan_id
= ?' at line 1
How can I fix that and send my query properly?
A solution for your problem is to use 'IN' inside your query:
var deleteRooms = [[3,23],[4,23],[5,23], [2,23]];
connection.query("DELETE FROM rate_plans_rooms WHERE (room_id, rate_plan_id) IN (?)",
[deleteRooms],function(err,results){
if(err) return console.log(err)
else console.log('sended');
});
The accepted solution did not work for me as it would give an Error: ER_OPERAND_COLUMNS: Operand should contain 2 column(s) error. Instead, this worked for me:
var deleteRooms = [[3,23],[4,23],[5,23], [2,23]];
queryArray = Array(deleteRooms.length).fill('(?)'));
connection.query("DELETE FROM rate_plans_rooms WHERE (room_id, rate_plan_id) IN ("+queryArray.join(',')+")",
[deleteRooms],function(err,results){
if(err) return console.log(err)
else console.log('sended');
});
I have multiple CSVs; however, I'm having difficulty merging them as they all have the same headers. Here's an example.
CSV 1:
ID,COUNT
1,3037
2,394
3,141
5,352
7,31
CSV 2:
ID, COUNT
1,375
2,1178
3,1238
5,2907
6,231
7,2469
CSV 3:
ID, COUNT
1,675
2,7178
3,8238
6,431
7,6469
I need to combine all the CSV file on the ID, and create a new CSV with additional columns for each count column.
I've been testing it with 2 CSVs but I'm still not getting the right output.
with open('csv1.csv', 'r') as checkfile: #CSV Data is pulled from
checkfile_result = {record['ID']: record for record in csv.DictReader(checkfile)}
with open('csv2.csv', 'r') as infile:
#infile_result = {addCount['COUNT']: addCount for addCount in csv.Dictreader(infile)}
with open('Result.csv', 'w') as outfile:
reader = csv.DictReader(infile)
writer = csv.DictWriter(outfile, reader.fieldnames + ['COUNT'])
writer.writeheader()
for item in reader:
record = checkfile_result.get(item['ID'], None)
if record:
item['ID'] = record['COUNT'] # ???
item['COUNT'] = record['COUNT']
else:
item['COUNT'] = None
item['COUNT'] = None
writer.writerow(item)
However, with the above code, I get three columns, but the data from the first CSV is populated in both columns. For example.
Result.CSV *Notice the keys skipping the ID that doesn't exist in the CSV
ID, COUNT, COUNT
1, 3037, 3037
2, 394, 394
3,141, 141
5,352. 352
7,31, 31
The result should be:
ID, COUNT, COUNT
1,3037, 375
2,394, 1178
3,141, 1238
5,352, 2907
6, ,231
7,31, 2469
Etc etc
Any help will be greatly appreciated.
This works:
import csv
def read_csv(fobj):
reader = csv.DictReader(fobj, delimiter=',')
return {line['ID']: line['COUNT'] for line in reader}
with open('csv1.csv') as csv1, open('csv2.csv') as csv2, \
open('csv3.csv') as csv3, open('out.csv', 'w') as out:
data = [read_csv(fobj) for fobj in [csv1, csv2, csv3]]
all_keys = sorted(set(data[0]).union(data[1]).union(data[2]))
out.write('ID COUNT COUNT COUNT\n')
for key in all_keys:
counts = (entry.get(key, '') for entry in data)
out.write('{}, {}, {}, {}\n'.format(key, *tuple(counts)))
The content of the output file:
ID, COUNT, COUNT, COUNT
1, 3037, 375, 675
2, 394, 1178, 7178
3, 141, 1238, 8238
5, 352, 2907,
6, , 231, 431
7, 31, 2469, 6469
The Details
The function read_csv returns a dictionary with the ids as keys and the counst as values. We will use this function to read all three inputs. For example for csv1.csv
with open('csv1.csv') as csv1:
print(read_csv(csv1))
we get this result:
{'1': '3037', '3': '141', '2': '394', '5': '352', '7': '31'}
We need to have all keys. One way is to convert them to sets and use union to find the unique ones. We also sort them:
all_keys = sorted(set(data[0]).union(data[1]).union(data[2]))
['1', '2', '3', '5', '6', '7']
In the loop over all keys, we retrieve the count using entry.get(key, ''). If the key is not contained, we get an empty string. Look at the output file. You see just commas and no values at places were no value was found in the input. We use a generator expression so we don't have to re-type everything three times:
counts = (entry.get(key, '') for entry in data)
This is the content of one of the generators:
list(counts)
('3037', '375', '675')
Finally, we write to our output file. The * converts a tuple like this ('3037', '375', '675') into three arguments, i.e. .format() is called like this .format(key, '3037', '375', '675'):
out.write('{}, {}, {}, {}\n'.format(key, *tuple(counts)))
I am new on CakePHP and facing a problem with SQL Alias.
I want to make an Excel file to generate a report from the MySQL database.
/**
* Generate transaction report
*
* #param none
*
* #return void
*/
public function generateReport()
{
//Getting data from the database to generate the report in Excel file
$data = $this->AchTransaction->find('all', array(
//'conditions' => $searchCondition,
'fields' => array(
"payee_name AS PAYEENAME",
'reference AS REFERENCE',
'reference2 AS REFERENCE2',
'currency AS CURRENCY',
'amount AS PAYOUTAMOUNT',
'bank_name AS BANKNAME',
'bank_branch_name AS BANKBRANCHNAME',
'bank_address AS BANKADDRESS',
'bank_country AS BANKCOUNTRY',
'account_name AS ACCOUNTNAME',
'account_class AS ACCOUNTCLASS',
'account_type AS ACCOUNTTYPE',
'bank_routing_number AS BANKROUTING',
'account_number AS ACCOUNT',
'beneficiary_address AS BENEFICIARYADDRESS',
'beneficiary_city AS BENEFICIARYCITY',
'beneficiary_state AS BENEFICIARYSTATE',
'beneficiary_postcode AS BENEFICIARYZIPCODE',
'beneficiary_country AS BENEFICIARYCOUNTRY',
'note as NOTE'
),
'order' => array('AchTransaction.id DESC')
));
// Generating Excel file
$this->Common->generateReport($data);
}
I am able to generate the Excel but having only one problem in alias, As you can see
"payee_name AS PAYEENAME",
Here the payee_name is the name of column or field in MySQL table, and I want this as PAYEE NAME, but when I write:
"payee_name AS PAYEE NAME",
I am getting this MySQL error:
Database Error
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'payee_name AS PAYEE NAME' in 'field list'
SQL Query: SELECT `payee_name AS PAYEE NAME`, `reference` AS `REFERENCE`, `reference2` AS `REFERENCE2`, `currency` AS `CURRENCY`, `amount` AS `PAYOUTAMOUNT`, `bank_name` AS `BANKNAME`, `bank_branch_name` AS `BANKBRANCHNAME`, `bank_address` AS `BANKADDRESS`, `bank_country` AS `BANKCOUNTRY`, `account_name` AS `ACCOUNTNAME`, `account_class` AS `ACCOUNTCLASS`, `account_type` AS `ACCOUNTTYPE`, `bank_routing_number` AS `BANKROUTING`, `account_number` AS `ACCOUNT`, `beneficiary_address` AS `BENEFICIARYADDRESS`, `beneficiary_city` AS `BENEFICIARYCITY`, `beneficiary_state` AS `BENEFICIARYSTATE`, `beneficiary_postcode` AS `BENEFICIARYZIPCODE`, `beneficiary_country` AS `BENEFICIARYCOUNTRY`, `note` AS `NOTE` FROM `aramor_payments`.`ach_transactions` AS `AchTransaction` WHERE 1 = 1 ORDER BY `AchTransaction`.`id` DESC
Notice: If you want to customize this error message, create app\View\Errors\pdo_error.ctp
Stack Trace
CORE\Cake\Model\Datasource\DboSource.php line 461 → PDOStatement->execute(array)
CORE\Cake\Model\Datasource\DboSource.php line 427 → DboSource->_execute(string, array)
CORE\Cake\Model\Datasource\DboSource.php line 671 → DboSource->execute(string, array, array)
CORE\Cake\Model\Datasource\DboSource.php line 1082 → DboSource->fetchAll(string, boolean)
CORE\Cake\Model\Model.php line 2631 → DboSource->read(AchTransaction, array)
APP\Controller\AchtransactionsController.php line 353 → Model->find(string, array)
[internal function] → AchtransactionsController->generateReport()
CORE\Cake\Controller\Controller.php line 485 → ReflectionMethod->invokeArgs(AchtransactionsController, array)
CORE\Cake\Routing\Dispatcher.php line 186 → Controller->invokeAction(CakeRequest)
CORE\Cake\Routing\Dispatcher.php line 161 → Dispatcher->_invoke(AchtransactionsController, CakeRequest, CakeResponse)
APP\webroot\index.php line 92 → Dispatcher->dispatch(CakeRequest, CakeResponse)
Can you please help me to get the name of payee_name field as PAYEE NAME?
Change
"payee_name AS PAYEE NAME",
to
"`payee_name` AS `PAYEE NAME`"
Another option is using virtualFields
$this->AchTransaction->virtualFields['PAYEE NAME'] = 'payee_name';
array('fields' => array('PAYEE NAME', 'etc'))