I have used the following package
import MSSQL from 'react-native-mssql';
near the above package on hover, it shows
Could not find a declaration file for module 'react-native-mssql'. 'd:/React Native Apps/Login/node_modules/react-native-mssql/index.android.js' implicitly has an 'any' type.
Try npm install #types/react-native-mssql if it exists or add a new declaration (.d.ts) file containing declare module 'react-native-mssql';
module "d:/React Native Apps/Login/node_modules/react-native-mssql/index.android
I have tried installing as mentioned above but nothing works.
And in code, I am getting an error at below line.
MSSQL.connect(config);
error is following
undeined is not an object (evaluating '_reactNativeMssql2.default.connect')
Please tell me how do I connect to MSSQL with react-native.
react-native-mssql can be installed with npm install --save react-native-mssql
then edit file android/settings.gradle and add:
include ':react-native-mssql'
project(':react-native-mssql').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mssql/android')
as well as file android/app/build.gradle:
dependencies {
...
implementation project(':react-native-mssql')
}
then it can be added to the packages list:
...
import com.stonem.mssql.MSSQLPackage;
...
#Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
...
.addPackage(new MSSQLPackage())
...
);
}
and then connected:
import MSSQL from 'react-native-mssql';
...
let config = {
server: '192.168.1.1', // ip address of the mssql database
username: 'sa', // username to login to the database
password: 'password', // password to login to the database
database: 'admin', // the name of the database to connect to
port: 1234 // OPTIONAL, port of the database on the server
}
MSSQL.connect(config);
an example for a SELECT query:
let query = 'SELECT TOP * FROM USERS'
MSSQL.executeQuery(query);
and one for an UPDATE query:
let query = 'UPDATE USERS SET Active=0'
MSSQL.executeUpdate(query);
make sure to call MSSQL.close(); once the connection isn't required anymore.
You could use "react-native link react-native-mssql" in the command prompt after using "cd Project_Name" to fix the issue, if 'Could not find a declaration file for module 'react-native-mssql' was your issue all along.
Related
I get the following error when connecting to my database:
" Caused by: org.postgresql.util.PSQLException: Something unusual has occurred to cause the driver to fail. Please report this exception."
package code.with.cal.timeronservicetutorial
import kotlinx.android.synthetic.main.activity_main.*
import java.sql.DriverManager
class ConnectionHelper {
fun ConnectDB() {
val jdbcUrl = "jdbc:postgresql://HOST/USER"
// get the connection
val connection = DriverManager.getConnection(jdbcUrl, "USER", "PW")
// prints true if the connection is valid
println(connection.isValid(0))
}
}
I suspect I didn't include the dependency of right version in my gradle, but i don't know how to find which driver version i have. I added this one:
implementation 'org.postgresql:postgresql:42.2.5'
I'm using doctrine in a project (not symfony). In this project I also use phpstan, i installed both phpstan/phpstan-doctrine and phpstan/extension-installer.
My phpstan.neon is like this:
parameters:
level: 8
paths:
- src/
doctrine:
objectManagerLoader: tests/object-manager.php
Inside tests/object-manager.php it return the result of a call to a function that return the entity manager.
Here is the code that create the entity manager
$database_url = $_ENV['DATABASE_URL'];
$isDevMode = $this->isDevMode();
$proxyDir = null;
$cache = null;
$useSimpleAnnotationReader = false;
$config = Setup::createAnnotationMetadataConfiguration(
[$this->getProjectDirectory() . '/src'],
$isDevMode,
$proxyDir,
$cache,
$useSimpleAnnotationReader
);
// database configuration parameters
$conn = [
'url' => $database_url,
];
// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);
When i run vendor/bin/phpstan analyze i get this error:
Internal error: An exception occurred in the driver: SQLSTATE[08006] [7] could not translate host name "postgres_db" to address: nodename nor servname provided, or not known
This appear because i'm using docker and my database url is postgres://user:password#postgres_db/database postgres_db is the name of my database container so the hostname is known inside the docker container.
When i run phpstan inside the container i do not have the error.
So is there a way to run phpstan outside docker ? Because i'm pretty sure that when i'll push my code the github workflow will fail because of this
Do phpstan need to try to reach the database ?
I opened an issue on the github of phpstan-doctrine and i had an answer by #jlherren that explained :
The problem is that Doctrine needs to know what version of the DB server it is working with in order to instantiate the correct AbstractPlatform implementation, of which there are several available for the same DB vendor (e.g. PostgreSQL94Platform or PostgreSQL100Platform for postgres, and similarly for other DB drivers). To auto-detect this information, it will simply connect to the DB and query the version.
I just changed my database url from:
DATABASE_URL=postgres://user:password#database_ip/database
To:
DATABASE_URL=postgres://user:password#database_ip/database?serverVersion=14.2
I create subdomain in plesk by Install project from Nuget That is in the following link: https://github.com/c1982/plesklib
var client = new PleskClient("IP", "UserName", "Password");
var resultSubdomain = client.CreateSubdomain("subdomain.com","SubDomainName");
but when trying to create database in to the interface for a subdomain that was already present in the interface by this command:
var result= client.CreateDatabase("subdomain.com", "databaseName" ,"databaseType for example:mssql");
the following erro occurs:
Request is invalid. Error in line 5: Element 'webspace-id': '0' is not a valid value of the atomic type 'id_type'.
what is wrong?
Thanks in Advance...
I'm trying to use SQL views with Doctrine.
Everything works fine so far, but I have a problem when running a basic fixtures load (with no options). I get the following error messages.
[Doctrine\DBAL\DBALException]
An exception occurred while executing 'DELETE FROM gp_items':
SQLSTATE[42000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]View or function 'gp_items' is not updatable
because the modification affects multiple base tables.
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]View or function 'gp_items' is not updatable
because the modification affects multiple base tables.
[PDOException]
SQLSTATE[42000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]View or function 'gp_items' is not updatable
because the modification affects multiple base tables.
I looked at the code that loads the fixtures from the bundle ("doctrine/doctrine-fixtures-bundle": "^2.3") and I think I have to alter something to the ORMPurger (Doctrine\Common\DataFixtures\Purger) but I'm not sure how to go about that.
So I would like to know how to override a function in that specific class.
Cheers!
Ok,
So I decided to fork the DoctrineFixturesBundle and use my own version of it in my project.
https://github.com/jbonnier/DoctrineFixturesBundle
In order for composer to use it, I modified my composer.json file adding the following code before the last closing bracket.
,
"repositories": [
{
"type": "vcs",
"url": "https://github.com/jbonnier/DoctrineFixturesBundle"
}
]
I also change my require-dev statement to use my personnal branch.
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "dev-jbonnier",
...
}
EDIT:
Additional explanation.
I'm currently working with version v2.4.1 of the bundle.
Here's the change I made to it.
File : Command/LoadDataFixturesDoctrineCommand.php
Changed line 113
from
$purger = new ORMPurger($em);
to
$purger = new ORMPurger($em, $this->listViews($input->getOption('em')));
Add function to class after line 136
/**
* Return an array with all views names in the database.
*
* #return array
*/
protected function listViews($entityManager)
{
$em = $this->getContainer()->get('doctrine')->getManager($entityManager);
$conn = $em->getConnection();
$sm = $conn->getSchemaManager();
$views = $sm->listViews();
$rst = array();
foreach ($views as $view)
{
array_push($rst, $view->getName());
}
return $rst;
}
I had a similar problem. I was lazy so I did the workaround to load our fixtures this way.
I you find a clean solution I'm interested
bin/console -e=test doctrine:database:drop --if-exists --force
bin/console -e=test doctrine:database:create --if-not-exists --no-interaction
bin/console -e=test doctrine:migrations:migrate --no-interaction
bin/console -e=test doctrine:fixtures:load --append --no-interaction
I am trying to use sequelize and sequelize-cli to create database schema changes (MSSQL) by using the migration mechanism. But nothing is happening - it looks like it does not find any migration files in the migration folder.
I did the following in a new folder to create a test project:
npm init
[ added relevant packages: sequelize, sequelize-cli, tedious ]
sequelize init
[ here I added the connection information, all to a blank database on Azure SQL ]
sequelize init:models
sequelize init:migrations
sequelize migration:create
I added the following to the created migration file:
'use strict';
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.createTable('users', { id: Sequelize.INTEGER });
},
down: function (queryInterface, Sequelize) {
return queryInterface.dropTable('users');
}
};
which is basically just according to the template created by the last sequelize command.
Now I would expect a new table to be created when I run the migrate command:
sequelize db:migrate
But all I get is this:
Sequelize [Node: 0.12.2, CLI: 1.7.4, ORM: 3.5.1]
Loaded configuration file "config/config.json".
Using environment "development".
Using gulpfile /usr/local/lib/node_modules/sequelize-cli/lib/gulpfile.js
Finished 'db:migrate' after 161 ms
which means it did not find any migration files. No table has appeared in the database and no sequelizeMeta table was created.
What's wrong?
You can try creating a .sequelizerc file in the root directory to point it to the correct migrations folder:
var path = require('path');
module.exports = {
'config': path.resolve('path/to/folder', 'config/config.json'),
'migrations-path': path.resolve('path/to/folder', 'migrations'),
'models-path': path.resolve('path/to/folder, 'models')
}
Run sequelize init after creating file