Good morning.
I'm with a problem that I can't figure out. The situation is the following:
I have a procedure that I call passing it a string, which is basically the name of a table.
In this particular case it is "sys".
This procedure basically executes the following lines:
Query.Close ();
Query.ParamByName ('TABLE'). AsString: = Table;
Query.Open;
"Query" basically has this:
SELECT * FROM: TABLE;
Therefore you should run the following:
SELECT * FROM sys;
Truth?
Well, apparently I'm having a bug. Since when testing it and executing my procedure this happens:
[FireDAC] [Phys] [SQLite] ERROR: near ": TABLE:" syntax error.
** Does SQLite work differently with parameters? **
I can not find why it fails.
Base of SQLite document and this link you can't pass table name as parameter:
[https://stackoverflow.com/questions/5870284/can-i-use-parameters-for-the-table-name-in-sqlite3][1]
Instead of that you can make your string of query by this manner(trick):
Query.sql[1]:='tablename'
Default query string my be like this:
select * form
//X (line 1 )
where ....
Related
I have a field in my acore_characters table named 'rank' with a tinyint which ranges from 0 to 3 inclusive, based on player's progression. I need to read that value at both login and at certain specific circumstances.
I wrote the following PreparedStatement: "SELECT rank FROM acore_characters WHERE guid = ?" and then the code which is supposed to read that value:
uint16 GetCharactersRank(uint64 guid) {
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(mystatement);
stmt->setUInt32(0, GetGUID());
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result) {
[...truncated]
and then fetching the result and so on, but then I get a code C8361 when compiling because 'GetGUID':identifier not found in Player.cpp file...what goes wrong? The other GetGUID calls throughout the file dont give this result. I'm not very fond of c++, any help is very appreciated.
It's not recommended to directly patch the core to add customisations to it. Instead, use modules.
An example can be found here: Is it possible to turn a core patch into a module for AzerothCore?
You can have a look and copy the skeleton-module and start modifying it to create your own.
In your case, you probably want to use the OnLogin player hook.
I have a migration written that executes just fine on my test database - did dozens of tests runs without issue. I run it on a clone of my prod database and all of a sudden I'm having all sorts of problems. I'm beginning to think its a database config or permissions issue, but I'm logged into this clone as root, so I'm not even sure where to start looking...
If I copy the mysql statement from the error (...and fix the missing data) the statement executes without issue.
ALTER TABLE `retail_items-tmp_09-10-2020` CHANGE original_inventory initial_inventory INT DEFAULT NULL;
The offending line:
Schema::table('retail_items-tmp_09-10-2020', function($table) {
$table->renameColumn('original_inventory','initial_inventory');
});
The Error:
[PDOException (42000)]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-tmp_09-10-2020 CHANGE original_inventory initial_inventory INT DEFAULT NULL' at line 1
The migration:
public function up()
{
/* 1. Backup Existing Tables */
DB::statement('CREATE TABLE `retail_items-tmp_09-10-2020` LIKE `retail_items`; ');
DB::statement('CREATE TABLE `ARCH__retail_items_09-10-2020` LIKE `retail_items`; ');
DB::statement('INSERT INTO `retail_items-tmp_09-10-2020` SELECT * FROM `retail_items`; ');
DB::statement('INSERT INTO `ARCH__retail_items_09-10-2020` SELECT * FROM `retail_items`;');
/* 2. Update structure */
Schema::table('retail_items-tmp_09-10-2020', function($table) {
$table->renameColumn('original_inventory','initial_inventory');
});
Schema::table('retail_items-tmp_09-10-2020', function($table) {
$table->integer('event_ID')->length(11)->unsigned()->nullable();
$table->foreign('event_ID')->references('event_ID')->on('events');
});
/* 3. Update structure that would have been destructive prior to step 3 */
// When I had this piece of code included, it resulted in the same error "Syntax error or access violation..." this worked in testing, but throws errors on Prod, changed to DB:statement below with success.
// Schema::table('retail_items-tmp_09-10-2020', function($table) {
// $table->smallInteger('flag')->unsigned()->nullable(false)->default(0)->change();
// });
$query = "ALTER TABLE `retail_items-tmp_09-10-2020` CHANGE `flag` `flag` SMALLINT(11) DEFAULT 0 NOT NULL; ";
DB::statement($query);
}
I've been stuck on this for a bit, so any theories, places to look, etc would be appreciated.
(I have another migration that renames the temp table at the end of this. I have a few migrations and data operations that all together take ~ 10+ min to execute with the piece of code that I'm launching this with, so the temp tables are necessary to prevent downtime when launching in production)
I still ended up having more troubleshooting/ other roadblocks on this issue, so this only removed one...
Even though they were properly quoted, I read a number of S.O. posts on the subject and as Webtect suggests I did end up simply removing all the dashes and things worked much more consistently and reliably. I'm still feel like it's a mystery as to why this happened because I've used hyphens in dates like this before - properly quoted - without issue. But this one sure threw me for a loop. I think I will entirely stop the practice of using hyphens in dated-table-names going forward. They seem to cause more headaches than the improved readability warrants.
I need to trim instance name from complete dblink name .For example The select query returns result like HHVISDEV.TRINITI.COM. I need to get HHVISDEV. And ofcourse There are such multiple results. So I need to use cursor and print the final result. I am getting Warning: Procedure created with compilation errors., when I compile. And when I call the procedure I am getting ERROR at line 1:
ORA-06575: Package or function DELETEDBLINKS1 is in an invalid state. Can any one please guide me.
create or replace procedure DeleteDBLinks1 is
cursor mycursor is
SELECT SUBSTR(DB_LINK, 1, INSTR(DB_LINK, '.', 1, 1) - 1)
FROM dba_db_links;
myvar dba_db_links.dblinks%TYPE;
BEGIN
OPEN mycursor;
LOOP
FETCH mycursor
INTO myvar;
EXIT WHEN mycursor%NOTFOUND;
DBMS_OUTPUT.put_line(myvar);
END LOOP;
CLOSE mycursor;
end;
/
If you see Warning: Procedure created with compilation errors, then, I can guess, you compile your procedure in SQL*Plus. In SQL*Plus you can run command
show errors
and you will see errors list. Your procedure looks OK, so I think problem is - you have no access to dba_db_links view. Try to use all_db_links or user_db_links instead.
Along with what Dmitry said about you probably not having access to dba_db_links table, you also had a typo in the myvar variable definition. It should have been:
myvar dba_db_links.db_link%TYPE;
SQL*Plus> SHOW ERRORS will help you in your PL/SQL endeavors, until you start using a PL/SQL IDE like SQL Developer or (my favorite) PL/SQL Developer, which will show you the errors automatically.
Stripped down, what I trying to do it the following
set selectQuery "SELECT col1, col2 FROM tableName"
db1 eval $selectQuery {
set insertQuery "INSERT INTO tableName VALUES($col1, $col2)"
db2 eval $insertQuery {
# Do trivial stuff to show progress
}
}
which basically copies the content of db1.tableName to db2.tableName.
The problem is that in my case, most of the content of db1.tableName already exists in db2.tableName. So basically, I just want to copy what doesn't exist yet so I thought I would just insert everything and let the inserts fail when the data's already there. This doesn't work because the whole script stops as soon as one insert fails. I tried using catch to ignore the failure and allow the script to continue, but I haven't been successful. Any ideas?
Also, there may be a better way to copy the contents of db1.tableName to db2.tableName without copying what's already there... Any help will be appreciated!
Shawn
P.S If you have ideas for a better title, that would be useful as well..
Sqlite has a INSERT OR REPLACE INTO construct which may be useful in this case.
http://www.sqlite.org/lang_insert.html
While I'm not familiar with your database api commands, so I can't comment on how you're looping throught the query results, but I can suggest a few things.
First, try catch again. I always find the usage a bit strange, but eventually you get used to it. Here's an example:
if { [catch { db2 eval $insertQuery} errmsg] } {
#There was an error - it is stored in $errmsg"
} else {
#success! Congratulations.
}
In your case, I imagine you just want to ignore any insert errors, so you can simply do:
set selectQuery "SELECT col1, col2 FROM tableName"
db1 eval $selectQuery {
set insertQuery "INSERT INTO tableName VALUES($col1, $col2)"
if { ![catch { db2 eval $insertQuery} errmsg] } {
# Do trivial stuff to show progress
}
}
You could also try doing the query first and putting the query results in a TCL list (or list of lists) - then do a foreach on the list, doing the inserts. Sometimes databases can be funny about mutating data, although it doesn't look at all like that is happening in your case.
I am trying to build simple XML database (inside BaseX or eXist-db), but I have trouble figuring how to modify values in document :
content is simple as this for test :
<p>
<pl>
<id>6></id>
</pl>
</p>
I am trying to build something like function which would insert element into <pl> if that element is not present or replace it if it is present. But XQuery is giving me troubles yet :
When I try it head-on with if-then-else logic :
if (exists(/p/pl[id=6]/name)=false)
then insert node <name>thenname</name> into /p/pl[id=6]
else replace value of node /p/pl[id=6]/name with 'elsename'
I get error Error: [XUDY0027] Replace target must not be empty. Clearly I am confused, why the else part is evaluated in both cases, thus the error.
When I empty out the else part :
if (exists(/p/pl[id=6]/name)=true)
then insert node <name>thenname</name> into /p/pl[id=6]
else <dummy/>
Then I get Error: [XUST0001] If expression: no updating expression allowed.
When I try through declaring updating function, even then it reports error :
declare namespace testa='test';
declare updating function testa:bid($a, $b)
{
if (exists(/p/pl[id=6]/name)=true)
then insert node <name>thenname</name> into /p/pl[id=6]
else <dummy/>
};
testa:bid(0,0)
Error: [XUST0001] If expression: no updating expression allowed.
I've got these errors from BaseX 6.5.1 package.
So how can I modify values in a simple fashion if possible ?
If I call insert straight, the there could be multiple elements of same value.
If I call replace it will fail when the node does not exist.
If I delete the node before insert/replace then I could destroy sub-nodes which I don't want.
In most SQL databases, these are quite simple task (like MYSQL 'replace' command).
#Qiqi: #Alejandro is right. Your if expression is incorrect XQuery syntax:
if (exists(/p/pl[id=6]/name))
then insert node <name>thenname</name> into /p/pl[id=6]
else replace value of node /p/pl[id=6]/name with 'elsename'
Note that eXist-db's XQuery Update functionality is currently an eXist-specific implementation, so in eXist (currently) 1.4.x and 1.5dev, you'll want:
if (exists(/p/pl[id=6]/name))
then update insert <name>thenname</name> into /p/pl[id=6]
else update value /p/pl[id=6]/name with 'elsename'
This eXist-specific XQuery Update syntax is documented on http://exist-db.org/update_ext.html. This syntax was developed before the W3C XQuery Update spec had reached its current state. The eXist team plans to make eXist fully compliant with the W3C spec soon, but in the meantime the docs above should help you achieve what you need to if you use eXist.
Note too that your example code contains a typo inside the pl and id elements. The valid XML version would be:
<p>
<pl>
<id>6</id>
</pl>
</p>