SQLSTATE[22021]: Character not in repertoire - database

I'm having this problem while seeding my PGSQL Database:
Illuminate\Database\QueryException : SQLSTATE[22021]: Character not in repertoire: 7 ERROR: secuencia de bytes no válida para codificación «UTF8»: 0xe3 0x83 0xe2 (SQL: insert into "races" ("name", "public_name", "members", "updated_at", "created_at") values (harp��a, Harpía, 23, 2018-04-21 20:30:20, 2018-04-21 20:30:20) returning "id")
at C:\Sandbox\rpgforum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 PDOException::("SQLSTATE[22021]: Character not in repertoire: 7 ERROR: secuencia de bytes no válida para codificación «UTF8»: 0xe3 0x83 0xe2")
C:\Sandbox\rpgforum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:330
2 PDOStatement::execute()
C:\Sandbox\rpgforum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:330
Please use the argument -v to see more details.
And this is my Seeder's code:
<?php
use Illuminate\Database\Seeder;
use App\Models\Race;
class RaceTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* #return void
*/
public function run()
{
$races = [
'Humano',
'Orco',
'Elfo',
'Harpía',
'Enano',
];
for ($i = 0; $i < count($races); $i++) {
$race_i = utf8_encode($races[$i]);
$race = Race::create([
'name' => strtolower($race_i),
'public_name' => $race_i,
'members' => mt_rand(10,30),
]);
} // for
}
}
My database configuration:
pgsql database
My config.database file config:
config.database file
Is there any solution for this problem? I can find the way to get rid of this problem...
EDIT:
I just noticed something weird. I got two records in my database:
database records
And both of them have symbols that gave me problem with the seeder. Maybe the problem is within the seeders logic? I'm doing the exact same thing I do the whole time with my Laravel/Postgresql projects so i can't find the reason why i can't seed words with accent mark but i can use a simple form to store that kind of information. Any ideas ?

Related

laravel Maximum execution time of 60 seconds exceeded --

hello guys so I am doing a laravel project ( new to laravel ).
i am supposed to to calculation from other tables and save the results in another OUTPUT table.
I have 8 calculation in total in each line and up to 3k lines to fill.
The problem that I get the ma execution time error 60 sec even if a change it in laravel and php.ini.
each function called is just calling a select where and sum I've decided to divide them for better org.
My question is is there a better way to process the data and minimize to exc time if you can help .
public function calcul($week)
{ $test = Output::where('week',$week)->Limit(1);
if($test->first()){
return self::afficher($week);
}
else{
DB::table('article')->orderBy('material')->chunk(100, function ($stocks){
foreach ($stocks as $stock) {
$id = $stock->material;
$safe_stock=self::safe_stock($id);
$past_need=self::PassedNeeds($id) - self::NeedsInTwoWeeks($id);
$two_week_need=self::NeedsInTwoWeeks($id);
$stock_=self::stock($id);
$bdl=self::bdl($id);
$sm=self::sm($id);
$package=self::package($id);
$store_1=self::store_1($id);
$store_2=self::store_2($id);
$store_3=self::store_3($id);
Output::create([
'material' => $id,'safe_stock'=>$safe_stock,'past_need'=>$past_need,'two_week_need'=>$two_week_need,
'stock'=>$stock_,'bdl'=>$bdl,'sm'=>$sm,'package'=>$package,
'store_1'=>$store_1,'store_2'=>$store_2,'store_3'=>$store_3
]);
}
});
return self::index();
}
}

Perl Executing DBI execute in Loop

I have a perl script which prepares a statement with params 1,2,3,4 using DBI interface .The prepare statement executes a stored procedure with 4 params.Then it runs a foreach loop and does execute
If the parameters are not right the stored procedure throws error and execute fails. I am interested in printing a warning and proceeding to next set of params.
After the first execute failure for an "invalid parameter", I get "Attempt to initiate a new Adaptive Server operation with results pending" as errmsg in SQL execute for subsequent loop iteration.
foreach my $file (#filelist)
{
#.. get param1 , param2 , param3, param4 from $file
unless ( dbh->execute($param1,$param2,$param3,$param4) )
{
#print some warning
next;
}
}
How do I continue processing with this error?
These are the version I am using
>perl -MDBI -e 'DBI-> installed_versions;'
Perl : 5.010001 (x86_64-linux-thread-multi)
OS : linux (2.6.18-348.12.1.el5)
DBI : 1.609
DBD::Sybase : 1.15
DBD::Sponge : 12.010002
DBD::SQLite : 1.27
DBD::Proxy : install_driver(Proxy) failed: Can't locate RPC/PlClient.pm in #INC
DBD::Informix : 2013.0521
DBD::Gofer : 0.011565
DBD::File : 0.37
DBD::ExampleP : 12.010007
DBD::DBM : 0.03
I added { RaiseError => 0, PrintWarn => 1, PrintError => 1 } in the connect as suggested by mekazu, (The code is exact same as yours mekazu ) but it is not helping still getting the same error.
In foreach I get success,
iteration 1 no error
iteration 2 gives a stored procedure error
" Database execute failed. ERROR MESSAGE: Server message number=52001
severity=16 state=1 line=124 server=dev procedure=sp1 text=Data
Error:Invalid parameter: P1
iteration 3
Database execute failed. ERROR MESSAGE: OpenClient message: LAYER =
(0) ORIGIN = (0) SEVERITY = (78) NUMBER = (51) Server dev, database
dev Message String: Attempt to initiate a new Adaptive Server
operation with results pending
iteration 4
Database execute failed. ERROR MESSAGE: OpenClient message: LAYER =
(0) ORIGIN = (0) SEVERITY = (78) NUMBER = (51) Server dev, database
dev Message String: Attempt to initiate a new Adaptive Server
operation with results pending
Ensure you disable RaiseError (default: false) when creating the handle. You can use PrintWarn (default: false) and PrintError (default: true) to save you doing it yourself:
$dbh = DBI->connect($dsn, $user, $password,
{ RaiseError => 0, PrintWarn => 1, PrintError => 1 });
my $sth = $dbh->prepare($query);
foreach my $file (#filelist)
{
#.. get param1 , param2 , param3, param4 from $file
unless ( $sth->execute($param1,$param2,$param3,$param4) )
{
#warning already printed
next;
}
}

Drupal7 Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 24 bytes)

I have this code that connect an external mysql database and retun columns values
for ($i=0; $i < sizeof($Columns); $i++) {
//$Columns contains columns names in a current datatable $dt
$result3 = Database::getConnection()->query("SELECT ".$Columns[$i]." From ".$dt." ");
$field_values = array();
$index = 0;
while ($row = $result3->fetchAssoc()) {
$field_values [$index] = $row[$Columns[$i]];
//drupal_set_message($field_values[$index]);
$index++;
}
The code work fine for any data table except one that contains thousend of columns and evry column contains many values..In the case of this data table drupal display a fatal error related to the allowed memory:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 24 bytes) in C:\xampp\htdocs\.....
I want to escape this error by trying to get only a few columns so I did the next:
while ($row = $result3->fetchAssoc() && $index<=3) {
}
But drupal still displaying this error any idea how to avoid such an error?
It might be a good idea to use Batch API for this. But you will have to find the smallest chunk that could be processed without overloading your server. Since this is highly dependent on the data you have, and the data you "don't" have too ( future data ). You may want to split it up int o very very small chunks.
maybe you can,
<?php
for ($i=0; $i < sizeof($Columns); $i++) {
// Send to batch processing.
}
If that doesn't work, then you will have to,
<?php
for ($i=0; $i < sizeof($Columns); $i++) {
// Do a count query get max
// split into smaller batches using paging in SQL ( hint: LIMIT 0, 10).
foreach($pages as $page) {
// Send to batch processing.
}
}
Please refer to the Batch API documentation i had linked to, it explains how you could define batch process and pass your parameters to them.

Kohana 3.2 Call to undefined method Database_MySQL_Result::offset()

That happens when I try to play around with DB::select instead of ORM.
The query is returned as an object, but the error appears.
Code:
$bd_userdata -> offset($pagination -> offset) -> limit($pagination -> items_per_page) -> find_all() -> as_array();
Error:
ErrorException [ Fatal Error ]: Call to undefined method Database_MySQL_Result::offset()
Does it mean I have to count rows, before I send them to the offset in pagination?
When I try $query->count_all() I get the error message:
Undefined property: Database_Query_Builder_Select::$count_all
I tried count($query) but instead I got:
No tables used [ SELECT * LIMIT 4 OFFSET 0 ]
Here is the solution:
$results = DB::select('*')
->from('users')
->where('id', '=', 1)
->limit($pagination->items_per_page)
->offset($pagination->offset)->execute();
And a counter:
$count = $results->count_all();
I was doing it before, the other way around. That is why it did not work.
As you can see, execute() returns Database_Result object, which has no QBuilder's functionality. You must apply all conditions (where, limit, offset etc) before calling execute.
Here is a simple example with pagination:
// dont forget to apply reset(FALSE)!
$query = DB::select()->from('users')->where('username', '=', 'test')->reset(FALSE);
// counting rows
$row_count = $query->count_all();
// create pagination
$pagination = Pagination::factory(array(
'items_per_page' => 4,
'total_items' => $row_count,
));
// select rows using pagination's limit&offset
$users = $query->offset($pagination->offset)->limit($pagination->items_per_page)->execute();

opa database : how to know if value exists in database?

I'd like to know if a record is present in a database, using a field different from the key field.
I've try the following code :
function start()
{
jlog("start db query")
myType d1 = {A:"rabbit", B:"poney"};
/myDataBase/data[A == d1.A] = d1
jlog("db write done")
option opt = ?/myDataBase/data[B == "rabit"]
jlog("db query done")
match(opt)
{
case {none} : <>Nothing in db</>
case {some:data} : <>{data} in database</>
}
}
Server.start(
{port:8092, netmask:0.0.0.0, encryption: {no_encryption}, name:"test"},
[
{page: start, title: "test" }
]
)
But the server hang up, and never get to the line jlog("db query done"). I mispell "rabit" willingly. What should I've done ?
Thanks
Indeed it fails with your example, I have a "Match failure 8859742" exception, don't you see it?
But do not use ?/myDataBase/data[B == "rabit"] (which should have been rejected at compile time - bug report sent) but /myDataBase/data[B == "rabit"] which is a DbSet. The reason is when you don't use a primary key, then you can have more than one value in return, ie a set of values.
You can convert a dbset to an iter with DbSet.iterator. Then manipulate it with Iter: http://doc.opalang.org/module/stdlib.core.iter/Iter

Resources