I use PHPUnit to test by PDO wrapper. One of my tests is an integration test that proves that the abstraction layer produces the right syntax, or binds PDOStatement in the right way, etc. For this, I use an in-memory SQLite database, and declare ext-pdo_sqlite as a dev-dependency of my project.
When Github Actions runs a build, dependencies all get installed, hinting that pdo_sqlite is present on the system. This is further confirmed by the fact that the connection succeeds. However, when I run an insert query to set up my database, I get the following error:
PDOException: SQLSTATE[HY000]: General error: 1 no such column: TRUE
The query looks like this:
INSERT INTO `persons` (`id`, `name`, `dob`, `weight`, `is_dev`, `teeth`) VALUES (NULL, 'Anton', '1987-11-03', 71.3, TRUE, 31)
Table creation is done with PDO like this:
$pdo->exec("CREATE TABLE `$tableName` (`id` int(6) PRIMARY KEY, `name` varchar(255), `dob` datetime, `weight` float(5), `is_dev` bool, `teeth` int(2))");
This only manifests on CI, and local tests pass fine - even on the same PHP version as CI.
Any ideas? Am I just missing something in the syntax? Could it be that GH Actions has only a dummy implementation of SQLite or something?
Note: This is an open source project, and you can see everything, including the failing build, in dhii/pdo-query#1.
Related
I am using ssdt project (using VS2017 version - 15.1, SSDT version - 15.1.61702.140). I have a stored proc with compile time error but when I build, the build completes successfully.
Is there some project/vs setting that could be causing this behavior? Isn't this kind of scary?
Product table:
CREATE TABLE [dbo].[Product]
(
[Id] INT NOT NULL PRIMARY KEY,
[Name] VARCHAR(50) NULL
)
Stored proc:
CREATE PROCEDURE [dbo].[uspProductSelect]
#name VARCHAR(50) = ''
AS
SELECT * FROM Product as p where p.Name = #name;
use Database1_3; -- this causes compile time issue;
and Visual Studio tells me there is an issue in the error window:
SQL80001: a USE database statement is not allowed in a procedure, function or trigger.
But if I build the project, it completes successfully! This cannot be the right behavior.
One of our MariaDB users decided to copy a database via a shell script that pipes the output of a mysqldump to another table.
If you restore the mysqldump to a database that hasn't been created before, it works just fine. However, if you then drop that database, re-create it, and then try to run the script again, it throws the following error:
ERROR 1005 (HY000) at line 25: Can't create table
core_dev.addresses (errno: 121 "Duplicate key on write or update")
mysqldump: Got errno 32 on write
SHOW ENGINE INNODB STATUS yields the following insight:
2017-05-03 09:34:19 7f9929fb4b00 Error in foreign key constraint
creation for table core_dev.addresses. A foreign key constraint of
name core_dev.addresses_ibfk_2 already exists. (Note that
internally InnoDB adds 'databasename' in front of the user-defined
constraint name.) Note that InnoDB's FOREIGN KEY system tables store
constraint names as case-insensitive, with the MySQL standard
latin1_swedish_ci collation. If you create tables or databases whose
names differ only in the character case, then collisions in constraint
names can occur. Workaround: name your constraints explicitly with
unique names.
However, the core_dev database is entirely empty:
MariaDB [(none)]> SHOW TABLES IN core_dev;
Empty set (0.01 sec)
What could the problem be? I'm not able to replicate this problem on any of our other MariaDB 10.1 servers. The only difference is that this particular one is running on CentOS 6, while the others are on CentOS 7.
I'm using PLSQL Developer client to access my 11G Oracle database. My understanding is that these are the default packages that come with this version. However, if I try to declare a utl_file.file_type variable, I get the following error:
PLS-00201: identifier 'UTL_FILE' must be declared
My program:
declare
l utl_file.file_type;
begin
NULL;
end;
I've tried to declare, for instance, a DBMS_LOB.BFILE, and it compiled succesfully, that prooves that some other packages are imported in my block.
Aren't all Oracle default packages automatically imported?
My assumption that if it's yours database, you have got pass for user SYS. If it is, you should check if package utl_file is installed. You can connect by SYS and execute this statement
SELECT * FROM dba_objects WHERE object_name = 'UTL_FILE'
You should see if that package exists. Also you should see object type 'SYNONYM' with owner 'PUBLIC'. If package present in DB, but there is no synonym for it, you can create it using this statement
CREATE PUBLIC SYNONYM OF UTL_FILE FOR SYS.UTL_FILE
If there is no such package - you should install it, by executing script, which is located in
{ORACLE_HOME}/rdbms/admin/utlfile.sql
I'm trying to add rspec testing to an app I've already been working on. I've been following this tutorial: http://everydayrails.com/2012/03/19/testing-series-rspec-models-factory-girl.html which is from 2012, so I'm sure it was done using Rails 3. I installed rspec and capybara, ran bundle, and ran rails g rspec:install. I started writing the test of my Question model below, and when I ran it with rspec spec/models/question_spec.rb
I received the error: Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=test' to resolve this issue. I tried to run that and I received this error about one of my previous migrations:
== ChangeTestTypeInScores: migrating =========================================
-- change_column(:scores, :test_type, "boolean USING CAST(test_type AS boolean)")
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: near "USING": syntax error: CREATE TABLE "scores" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "test_type" boolean USING CAST(test_type AS boolean), "name" varchar(255), "created_at" datetime, "updated_at" datetime, "user_id" integer, "month" varchar(255), "year" varchar(255))
How can I correctly set up rspec without messing up my database, which works fine otherwise?
rails_helper.rb:
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
ActiveRecord::Migration.check_pending!
.rspec:
--color
--require spec_helper
--require rails_helper
--format documentation
question_spec.rb:
require 'spec_helper'
describe Question do
it "has a valid factory"
it "is invalid without a body"
it "is invalid without an answer"
end
I assume there's an issue with my changing the :test_type in my Scores model to boolean based on that error, but it all works great locally and on Heroku, so I don't want to mess with my database in order to run tests. Any help is appreciated.
UPDATE:
I added this to the test.rb file:
config.active_record.maintain_test_schema = false
Also, I updated my version of rails to 4.1.6 after seeing many other related Stack Overflow issues. Now I get this error:
/Users/tambe257/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load': cannot load such file -- /Users/tambe257/programming/rails_projects/fast_track/spec/models/question.rb (LoadError)
It looks like a problem with some dependencies, but I've been googling the error with no luck.
On the update above I added this to the test.rb file, which actually cleared things up:
config.active_record.maintain_test_schema = false
I was then getting the (LoadError), but that was due to my file name not being completely correct. When you enter something like this below, be sure the route and file name are correct!
rspec spec/models/question_spec.rb
When using korma.db, defdb can take a sqlite3 helper to establish a connexion to a sqlite3 database. However, I've tried placing the database on the root of the project directory, alongside project.clj, and on the resources directory, but when I try to use the db I get:
Failure to execute query with SQL:
SELECT "examples".* FROM "examples" :: []
SQLException:
Message: [SQLITE_ERROR] SQL error or missing database (no such table: examples)
Needless to say my sqlite database contains an examples table. When trying to do this, I get a sqlite.db file of zero bytes placed on the root project dir.
I'm doing this from lein repl within the project, by the way.
Edit: This is what I do when it fails:
(use 'korma.db)
(defdb db (sqlite3 {:db "filename.db"}))
(use 'korma.core)
(defentity examples)
(select examples)
Just in case anybody is wondering or runs into this...
Using version [korma "0.4.2"]
and [org.xerial/sqlite-jdbc "3.7.15-M1"]
in my project.clj:
My project structure looks like:
root/project.clj
root/db/dev.sqlite3
root/src/...
and this is how I use korma to access the db:
(use 'korma.db)
(defdb mydb {:classname "org.sqlite.JDBC"
:subprotocol "sqlite"
:subname "db/dev.sqlite3"})
Basically, using subname, I'm able to search in the root of the lein project. I added db/ in the subname per my dir structure above.