tablename

MySQL Variables storing database name

心已入冬 提交于 2019-12-01 09:16:50
问题 I have a long script that I need to run on several different databases (all witht he same tables and field names). What I would like to do is something like this: 1 SET @TARGET_DATABASE = 'beta' 2 SET @SOURCE_DATABASE = 'sandbox'; 3 4 CREATE DATABASE IF NOT EXISTS @TARGET_DATABASE; 5 USE @TARGET_DATABASE; ... 10 INSERT INTO `tableFoo` SELECT * FROM @SOURCE_DATABASE.`tableFoo`; On line 10 I get an error (I'm not surprised): "Script line: 10 You have an error in your SQL syntax; check the

Safe way to use table name as parameter in JDBC query

谁都会走 提交于 2019-12-01 00:43:45
What is the safe way how to put table name as parameter into SQL query? You cannot put table name as parameter using PreparedStatement . Concatenating string to execute query with dynamic table name using Statement is possible, however it is not recommended because of risk of SQL injection. What is the best approach to do this? I would try to solve the design problem, so you don't have to set the table name dynamically. If this is not possible, I would go for a design where you manage a list of available tables and users pick one from there, BY ID, so you can retrieve the real table name from

Safe way to use table name as parameter in JDBC query

怎甘沉沦 提交于 2019-11-30 18:07:30
问题 What is the safe way how to put table name as parameter into SQL query? You cannot put table name as parameter using PreparedStatement. Concatenating string to execute query with dynamic table name using Statement is possible, however it is not recommended because of risk of SQL injection. What is the best approach to do this? 回答1: I would try to solve the design problem, so you don't have to set the table name dynamically. If this is not possible, I would go for a design where you manage a

mysql (5.1) > create table with name from a variable

喜你入骨 提交于 2019-11-30 12:10:40
I'm trying to create a table with a name based on the current year and month( 2011-09 ), but MySQL doesn't seem to like this. SET @yyyy_mm=Year(NOW())+'-'+Month(NOW()); CREATE TABLE `survey`.`@yyyy_mm` LIKE `survey`.`interim`; SHOW TABLES IN `survey`; +-----------+ | interim | +-----------+ | @yyyy_mm | +-----------+ If I do CREATE TABLE; without the ticks around @yyyy_mm , I get a generic syntax error. @yyyy_mm resolves to 2020 . You should be able to do something like this: SET @yyyy_mm=DATE_FORMAT(now(),'%Y-%m'); SET @c = CONCAT('CREATE TABLE `survey`.`',@yyyy_mm, '` LIKE `survey`.`interim`

Entity Framework Core RC2 table name pluralization

随声附和 提交于 2019-11-28 19:11:14
Is there a way to do what this code did in EF Core RC 2? protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); } Morteza Manavi There is no convention for this as of EF RC2 build. This is from EF Core team: In past pre-release of EF Core, the table name for an entity was the same as the entity class name. In RC2 we now use the name of the DbSet property. If no DbSet property is defined for the given entity type, then the entity class name is used. Now if you want to revert back to the RC1 naming conventions for

Query a table that has spaces in its name

点点圈 提交于 2019-11-28 12:12:37
I have a situation, I have a Access table named Gas Flow Rates that I want to add records. When I try to run my insert query for a similar table Common Station , I get the following error: "error hy000: syntax error, in query incomplete query clause" Code is: using System; using System.Data.Odbc; class MainClass { static void Main(string[] args) { string connectionString = "Dsn=Gas_meter"; string sqlins = ""; OdbcConnection conn = new OdbcConnection(connectionString); OdbcCommand cmdnon = new OdbcCommand(sqlins, conn); conn.Open(); try { cmdnon.CommandText = "INSERT INTO 'Common station' (

Loop on tables with PL/pgSQL in Postgres 9.0+

强颜欢笑 提交于 2019-11-28 05:28:11
I want to loop through all my tables to count rows in each of them. The following query gets me an error: DO $$ DECLARE tables CURSOR FOR SELECT tablename FROM pg_tables WHERE tablename NOT LIKE 'pg_%' ORDER BY tablename; tablename varchar(100); nbRow int; BEGIN FOR tablename IN tables LOOP EXECUTE 'SELECT count(*) FROM ' || tablename INTO nbRow; -- Do something with nbRow END LOOP; END$$; Errors: ERROR: syntax error at or near ")" LINE 1: SELECT count(*) FROM (sql_features) ^ QUERY: SELECT count(*) FROM (sql_features) CONTEXT: PL/pgSQL function inline_code_block line 8 at EXECUTE statement

How to use dynamic table name in SELECT query using JDBC

不羁的心 提交于 2019-11-28 01:55:06
问题 I have 5 or table table to query from \ my syntax i like this String sql2 = "SELECT * FROM ? WHERE Patient_ID = ?"; pst = conn.prepareStatement(sql2); System.out.println("SQL before values are set "+sql2); System.out.println("The values of table/test name recieved in TestPrint stage 1 "+tblName); System.out.println("The values of test name recieved in TestPrint stage 1 "+key); // values are outputted correctly but are not getting set in the query pst.setString(1, tblName); pst.setLong(2, key)

LINQ Select from dynamic tableName string

会有一股神秘感。 提交于 2019-11-27 09:36:34
I want to get list of records from an entity model (I'm using EF version 5) with a particular accountID. I'm being supplied with the tableName string (this has to be dynamic) and the accountID. I'm trying the following 2 methods but none of them is working (giving me errors on the IQueryable object 'table': PropertyInfo info = _db.GetType().GetProperty(tableName); IQueryable table = info.GetValue(_db, null) as IQueryable; var query = table.Where(t => t.AccountID == accID) .Select(t => t); List <object> recList = ( from records in table where records.AccountID == accID select records).ToList

Query a table that has spaces in its name

余生长醉 提交于 2019-11-27 06:50:34
问题 I have a situation, I have a Access table named Gas Flow Rates that I want to add records. When I try to run my insert query for a similar table Common Station , I get the following error: "error hy000: syntax error, in query incomplete query clause" Code is: using System; using System.Data.Odbc; class MainClass { static void Main(string[] args) { string connectionString = "Dsn=Gas_meter"; string sqlins = ""; OdbcConnection conn = new OdbcConnection(connectionString); OdbcCommand cmdnon = new