function UpdateAttributes ( $index, $attrs, $values )
no, sphinx does not. numeric attributes only
Related
The TYPO3 QueryBuilder method createNamedParameter does only support a signed integer but no unsigned integer. There is not even a PDO constant for an unsigned integer. And TYPO3 seems to have no other constants like for the arrays Connection::PARAM_INT_ARRAY.
static public function checkDoublePostExist ($table, $doublePostField, $key)
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->setRestrictions(GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer::class));
$result =
$queryBuilder
->count('*')
->from($table)
->where(
$queryBuilder->expr()->eq($doublePostField, $queryBuilder->createNamedParameter($key, \PDO::PARAM_INT))
)
->execute()
->fetchColumn(0);
return $result;
}
The SQL field is defined as:
doublePostCheck int(11) unsigned DEFAULT '0' NOT NULL
The generated SQL will be like this:
SELECT COUNT(*) FROM `tt_board` WHERE (`doublePostCheck` = -1018532669) AND (`tt_board`.`deleted` = 0)
This is weird, because no negative values are allowed for this field. I am afraid that this query will not do the right thing.
Can the string format be used for an unsigned integer?
->where(
$queryBuilder->expr()->eq($doublePostField, $queryBuilder->createNamedParameter($key, \PDO::PARAM_STR))
)
The generated SQL would be correct:
SELECT COUNT(*) FROM `tt_board` WHERE (`doublePostCheck` = '3276434627') AND (`tt_board`.`deleted` = 0)
Which solution is the best for unsigned integers?
The problem is that your integer value is higher as the field int(11) can work with.
The maximum value for unsigned fields is 2147483647, see https://dev.mysql.com/doc/refman/8.0/en/integer-types.html. Your value (3276434627) is quite higher than this.
As PHP's integer maximum value is the same, it begins to start in negative area when the value is higher than maximum value.
The solution would be to change the database field to use bigint.
In SQL
DECLARE #Search VARCHAR(100) = ''
SELECT * FROM Customers WHERE #Search = '' OR FirstName like '%'+ #Search +'%'
Please help me out on this query, how to write this query in mongoDB
Well you will have to use $regex operator in mongodb in order to achieve that
your query would be some what like this
db.customers.find({"FirstName": /.*SearchTerm.*/})
I have a column as 'created_date' in the Database Table.
I am trying to select the record based on between two date as 'start-date' and 'end-date'
How can I write query as bellow in sphinx
SELECT * FROM table where created_date BETWEEN "2001-01-05" AND
"2001-01-10"
You can use setfilterrange
$cl->SetFilterRange ( $attribute, $min, $max, $exclude=false )
Here $cl is object of sphinx class, $min & max is your date range.
Hope this help !
I have a table in a SQLite database where a column stores file mtimes in epoch seconds.
I would now like to search in that table files that were modified in a certain month?
In raw SQL I would do:
select * from my_table where strftime('%Y-%m', mtime, "unixepoch") = "2009-08"
Is there a way to do this efficiently via DBIx::Class? Is it possible to do
$m->search({ \'strftime('%Y-%m', mtime, "unixepoch")' => "2009-08" })
I tried understanding if there's a way with DBIx::Class::InflateColumn::DateTime but I didn't find it.
Thanks
Simone
The syntax you're looking for is:
$m->search(
\[ q{strftime('%Y-%m', mtime, "unixepoch") = ?}, "2009-08" ]
);
Yes, that's an array-ref-ref. The first element is literal SQL which is permitted to use ? placeholders, and the remaining elements are values to bind to those placeholders, and DBIC will make sure to reorder everything internally so that those values get put into the right place in the bind list when the query runs.
If you need to combine one of these with other criteria, since an arrayrefref isn't a valid hash key, you need to use the -and syntax:
$m->search({
-and => [
foo => 'bar',
\[ q{ SQL }, $bind ],
],
});
Here is the section of the SQL::Abstract docs for this construct.
I would suggest you using search_literal instead:
# assuming $m isa DBIx::Class::ResultSet
$m->search_literal('strftime("%Y%m", mtime, "unixepoch") = ?', '200908');
EDIT: I stand corrected. Please refer to #hobbs' comment and answer.
How can I fetch the last row that was inserted using DBI (DBD::mysql)?
Code sample:
my $sth = $dbh->prepare('INSERT INTO a ( x, y, z ) VALUES ( ?, ?, ? )');
$sth->execute( $x, $y, $z );
How can I get access to the data that was inserted by the above prepare statement? I need to get the primary ID (AUTOINCREMENT) value.
UPDATE:
From DBD::mysql documentation:
An alternative way for accessing this
attribute is via
$dbh->{'mysql_insertid'}.
Thank you Manni and n0rd for your answers. :-)
This is a property of the statement handle. You should be able to access the ID like that:
$sth->{mysql_insertid}
A database agnostic approach is to use the DBI's last_insert_id method. This approach helps to reduce dependency on a specific database:
$dbh->last_insert_id
$rv = $dbh->last_insert_id($catalog, $schema, $table, $field);
Returns a value 'identifying' the row just inserted, if possible. Typically this would be a value assigned by the database server to a column with an auto_increment or serial type. Returns undef if the driver does not support the method or can't determine the value.
SELECT LAST_INSERT_ID() query will also return what you want.