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)
Related
I've the following table.
CREATE TABLE Worker (
WORKER_ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
FIRST_NAME CHAR(25),
LAST_NAME CHAR(25),
SALARY INT(15),
JOINING_DATE DATETIME,
DEPARTMENT CHAR(25)
);
INSERT INTO Worker
(WORKER_ID, FIRST_NAME, LAST_NAME, SALARY, JOINING_DATE, DEPARTMENT) VALUES
(001, 'Monika', 'Arora', 100000, '14-02-20 09.00.00', 'HR'),
(002, 'Niharika', 'Verma', 80000, '14-06-11 09.00.00', 'Admin'),
(003, 'Vishal', 'Singhal', 300000, '14-02-20 09.00.00', 'HR'),
(004, 'Amitabh', 'Singh', 500000, '14-02-20 09.00.00', 'Admin'),
(005, 'Vivek', 'Bhati', 500000, '14-06-11 09.00.00', 'Admin'),
(006, 'Vipul', 'Diwan', 200000, '14-06-11 09.00.00', 'Account'),
(007, 'Satish', 'Kumar', 75000, '14-01-20 09.00.00', 'Account'),
(008, 'Geetika', 'Chauhan', 90000, '14-04-11 09.00.00', 'Admin');
I'm looking for a way to get the desired result of the following question using the AND function.
Any solutions on the same would be appreciated.
Try this:
SELECT * from Wroker
WHERE RIGHT(FIRST_NAME, 1) = 'h'
AND LENGTH(FIRST_NAME) = 6
The shortest option is likely this (will become bad to read if the length increases from 6 to 10, 15 etc. due to many underscores):
SELECT *
FROM Worker
WHERE
FIRST_NAME LIKE '_____h'
Especially for a high length, I would avoid this and use LIKE and LENGTH:
SELECT *
FROM Worker
WHERE
LENGTH(FIRST_NAME) = 6 AND
FIRST_NAME LIKE '%h'
Another similar option is RIGHT and LENGTH:
SELECT *
FROM Worker
WHERE
LENGTH(FIRST_NAME) = 6 AND
RIGHT(FIRST_NAME,1) = 'h'
See here
Note: The answer assumes you just want to check whether exactly six characters appear. Edit your question - and if you know how - also the query - if this is not sufficient and you need to exactly check for example for six letters instead (ignoring spaces, digits etc.) or anything else.
An other way to do it using SUBSTRING to extract from the sixth character and check if equal h :
SELECT * from Worker
WHERE SUBSTRING(FIRST_NAME, 6) = 'h'
SELECT * FROM Worker
Where FIRST_NAME like "%h" and length(FIRST_NAME)=6
Take reference from image for the output
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 am trying to insert hundreds of rows into a MySQL db at once. There are two types of records, unanswered calls and answered calls. I am putting all records into a list of tuples, and each record is it's own tuple, so that I can use the executemany function. I am getting a TypeError: not all arguments converted during string formatting, and I don't understand why.
answered = []
unanswered = []
insertQuery = """ INSERT INTO cdr (recno, relcause, starttime, answertime, endtime, releasecausetext, releasecausecode, 1streleasedialog,
origtrunk, callingnumber, orighost, callednumber, desthost, origcallid, origremotepayloadip, origremotepayloadport,
origlocalpayloadip, origlocalpayloadport, termtrunk, termsourcenumber, termsourcehost, termdestnumber, termdesthostname,
termcallid, termremotepayloadip, termremotepayloadport, termlocalpayloadip, termlocalpayloadport, duration, postdialdelay,
ringtime, durationms, routetableused, origtidalias, termtidalias, termpddms, reasoncause, mappedcausecode, mappedreasoncause,
reasoncausetext, origmos, termmos) VALUES ('%s'); """
for y in cdrList:
#Check to make sure record does not exist
sqlQuery = "select * from cdr where recno = %d and origcallid = %s;" % (int(y[0]), y[13])
if cursor.execute(sqlQuery):
print("Record exists")
else:
if y[7]=='NA':
unanswered.append((y[0], y[5],extractSqlDate(y[6]), 'null', extractSqlDate(y[8]), y[10], y[11], y[12], y[13], y[15], y[16], y[17], y[18], y[19], y[20], y[21], y[22], y[23], y[32], y[34], y[35], y[36], y[37], y[38], y[39], y[40], y[41], y[42], y[53], y[54], y[55], y[56], y[60], y[66], y[67], y[71], y[78], y[79], y[80], y[81], y[85], y[88]))
else:
answered.append((y[0], y[5],extractSqlDate(y[6]), extractSqlDate(y[7]), extractSqlDate(y[8]), y[10], y[11], y[12], y[13], y[15], y[16], y[17], y[18], y[19], y[20], y[21], y[22], y[23], y[32], y[34], y[35], y[36], y[37], y[38], y[39], y[40], y[41], y[42], y[53], y[54], y[55], y[56], y[60], y[66], y[67], y[71], y[78], y[79], y[80], y[81], y[85], y[88]))
try:
print(answered)
cursor.executemany(insertQuery, answered)
cursor.executemany(insertQuery, unanswered)
db.commit()
print("Record inserted successfully")
except MySQLdb.Error as e:
print(e)
I have confirmed that each element in each tuple in the list is a string:
Successfully connected to database
/PATH/20190610/20190610-0015-1750147245-1750147250.cdr
[('1750147245', '0001', '2019-06-10 00:10:50', '2019-06-10 00:10:59', '2019-06-10 00:11:13', 'Normal BYE', ' 200', 'O', '001102', '+tn', 'ip', '+tn', 'ip', '273418599_83875291#ip', 'ip', '20530', 'ip', '11944', '000020', '+tn', 'ip', 'tn', 'ip', '4121333-0-2851866068#ip', 'ip', '16840', 'ip', '11946', '13', '1', '8', '13450', '50', 'C - Peerless C6933_04 Origin', 'P - Thirdlane 6', '1150', '', '200', '', '', '0', '0')]
I found the problem. The tuple was returning strings, so the insert query was trying to insert values like this: ''value''. I removed the ' around the %s, and, based on #jonrsharpe's comment, added %s for each other value, and it worked.
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))'
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'))