I have been trying since yesterday no where I am able to find a proper post how to upload file as blob to table.
Below is my table :
create table upload_file
(
fileblob blob,
filename varchar2(250),
mimetype varchar2(250),
createDate date
);
I have created a page name as Testing and Added below items
P1_CHOOSE_FILE [ file browse ]
P1_MIMETYPE [ Hidden ]
FILE_NAME [ Hidden ]
CREATED [ Hidden ]
On P1_CHOOSE_FILE , I set a property called : Blob column specified in Item source attribute
and value required as ON
Then created one Button with Dynamic action
Now my biggest challenge is How to insert my choose file to my upload_file table using PL/SQL code
I tried report with form but it does not work for me in APEX 20.x due to restrictions setting done to it. So want to achieve using PL/SQL code.
Please demonstrate with image and code and how to achieve it
Not sure if it will help you, but here's how I did on my application :
My table :
CREATE TABLE inv_tb_document(
pk_document INT, --primary key
nom_document VARCHAR(255) CONSTRAINT ct_nn_nom_document NOT NULL, --document name
blob_document BLOB CONSTRAINT ct_nn_blob_document NOT NULL, --blob column
mimetype_document VARCHAR(255) CONSTRAINT ct_nn_mimetype_document NOT NULL, --mimetype column
charset_document VARCHAR(255), --charset column
commentaire_document VARCHAR(75) CONSTRAINT ct_nn_commentaire_document NOT NULL, -- irrelevant for your case
date_document TIMESTAMP(8) CONSTRAINT ct_nn_date_doducment NOT NULL, --irrelevant too
CONSTRAINT ct_pk_document PRIMARY KEY(pk_document)
);
Now, here's what I did for my form :
Here are the attributes of my File Browser Item :
I don't have any custom code to insert the document on my tables, I hope this could help you anyway.
not an exact answer to your specific question, but if you change Storage Type as Table APEX_xx_Temp. you could go like this:
(select filename from apex_application_temp_files where name = :P1_CHOOSE_FILE)
,(select mime_type from apex_application_temp_files where name = :P1_CHOOSE_FILE)
,(select blob_content from apex_application_temp_files where name = :P1_CHOOSE_FILE)
Related
I've created a MySQL Model with a few tables, some of them with fk's to another table. I usually export the SQL from MySQL Model to my database using the "Forward Engineer SQL CREATE Script" inside File -> Export -> Forward Engineer SQL CREATE Script. The problem here is that when I generate the creation script, all my fk's become unique. I didn't check UQ option in MySQL Model but it creates a script with unique fk's anyway, so, I need to change the SQL file generated and remove all the unwanted uniques. Anyone has a clue why this is happening?
Generated script:
CREATE TABLE IF NOT EXISTS `u514786799_detranleiloes`.`Lotes` (
`createdAt` DATE NOT NULL,
`updatedAt` DATE NOT NULL,
`id` INT UNIQUE NOT NULL AUTO_INCREMENT,
`LeiloesId` INT UNIQUE NOT NULL,
`conservado` TINYINT NULL,
`numero` INT NOT NULL,
`CRDsId` INT UNIQUE NULL,
PRIMARY KEY (`id`),
INDEX `fk_Lotes_Leiloes_idx` (`LeiloesId` ASC),
INDEX `fk_Lotes_CRDs1_idx` (`CRDsId` ASC),
CONSTRAINT `fk_Lotes_Leiloes`
FOREIGN KEY (`LeiloesId`)
REFERENCES `u514786799_detranleiloes`.`Leiloes` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Lotes_CRDs1`
FOREIGN KEY (`CRDsId`)
REFERENCES `u514786799_detranleiloes`.`CRDs` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
AUTO_INCREMENT = 1;
Using django, I added a new entry to my table. Now I want to delete it using PHPPgAdmin (postgresql), but I get No unique Identifier for this row error. What is the problem?
django automatically adds an auto-incrementing primary key, so I cannot figure out what the issue is?
I read this post, but it did not help. If you notice the image carefully, you will see that the primary key column label is id but not pk as it should be in django.
EDIT: No primary key is seen on table;
But this is what django executes;
python manage.py sql auth
CREATE TABLE "auth_user" (
"id" serial NOT NULL PRIMARY KEY,
"password" varchar(128) NOT NULL,
"last_login" timestamp with time zone NOT NULL,
"is_superuser" boolean NOT NULL,
"username" varchar(30) NOT NULL UNIQUE,
"first_name" varchar(30) NOT NULL,
"last_name" varchar(30) NOT NULL,
"email" varchar(75) NOT NULL,
"is_staff" boolean NOT NULL,
"is_active" boolean NOT NULL,
"date_joined" timestamp with time zone NOT NULL
)
;
EDIT: A screenshot from PHPPgAdmin, showing id as primary key
I think this is a bug with phpPgAdmin.
I experienced a similar problem and went directly into psql (using the command ./manage.py dbshell).
I tried deleting the row in question, and received a more helpful error message than the one from phpPgAdmin. (In my case, that the row was being referenced by another table.)
I deleted the row referenced by the other table, and was then able to delete the row in question.
I've been trying to add a foreign key to my table using heidisql and I keep getting the error 1452.
After reading around I made sure all my tables were running on InnoDB as well as checking that they had the same datatype and the only way I can add my key is if I drop all my data which I don't intend to do since I have spent quite a few hours on this.
here is my table create code:
CREATE TABLE `data` (
`ID` INT(10) NOT NULL AUTO_INCREMENT,
#bunch of random other columns stripped out
`Ability_1` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
#more stripped tables
`Extra_Info` SET('1','2','3','Final','Legendary') NOT NULL DEFAULT '1' COLLATE 'utf8_unicode_ci',
PRIMARY KEY (`ID`),
UNIQUE INDEX `ID` (`ID`)
)
COLLATE='utf8_unicode_ci'
ENGINE=InnoDB
AUTO_INCREMENT=650;
here is table 2
CREATE TABLE `ability` (
`ability_ID` SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
#stripped columns
`Name_English` VARCHAR(12) NOT NULL COLLATE 'utf8_unicode_ci',
PRIMARY KEY (`ability_ID`),
UNIQUE INDEX `ability_ID` (`ability_ID`)
)
COLLATE='utf8_unicode_ci'
ENGINE=InnoDB
AUTO_INCREMENT=165;
Finally here is the create code along with the error.
ALTER TABLE `data`
ADD CONSTRAINT `Ability_1` FOREIGN KEY (`Ability_1`) REFERENCES `ability` (`ability_ID`) ON UPDATE CASCADE ON DELETE CASCADE;
/* SQL Error (1452): Cannot add or update a child row: a foreign key constraint fails (`check`.`#sql-ec0_2`, CONSTRAINT `Ability_1` FOREIGN KEY (`Ability_1`) REFERENCES `ability` (`ability_ID`) ON DELETE CASCADE ON UPDATE CASCADE) */
If there is anything else I can provide please let me know this is really bothering me. I'm also using 5.5.27 - MySQL Community Server (GPL) that came with xampp installer.
If you are using HeidiSQL it is pretty easy.
Just see the image, click on the +Add to add foreign keys.
I prefer GUI way of creating tables and its attribute because it saves time and reduces errors.
I found it. Sorry everyone. The problem was that I had 0 as a default value for my fields while my original table had no value for 0.
Here is how you can do it ;
Create your Primary keys. For me this was straight forward so I won't post how to do that here
To create your FOREIGN KEYS you need to change the table / engine type for each table from MyIASM to InnoDb. To do this Select the table on the right hand side then select the OPTIONS tab on the right hand side and change the engine from MyIASM to InnoDb for every table.
Really hate to use other people's time, but it seems the problem is just not going away.
I considered all recommendations at http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-create-table-mydbsql-328_45frm-errno-150/ and at http://forums.mysql.com/read.php?22,19755,19755#msg-19755 but nothing.
hope that someone points to a stupid mistake.
here are the tables:
CREATE TABLE IF NOT EXISTS `shop`.`category` (
`id` INT(11) NOT NULL AUTO_INCREMENT ,
`category_id` INT(11) NOT NULL ,
`parent_id` INT(11) NULL DEFAULT '0' ,
`lang_id` INT(11) NOT NULL ,
...other columns...
PRIMARY KEY (`id`, `category_id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_unicode_ci;
CREATE TABLE IF NOT EXISTS `shop`.`product_category` (
`category_id` INT(11) NOT NULL ,
`product_id` INT(11) NOT NULL ,
INDEX `fk_product_category_category1_zxc` (`category_id` ASC) ,
CONSTRAINT `fk_product_category_category1_zxc`
FOREIGN KEY (`category_id` )
REFERENCES `shop`.`category` (`category_id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_unicode_ci;
Error Code: 1005. Can't create table 'shop.product_category' (errno: 150)
You need an index on category_id in the category table (I see it's part of the primary key, but since it's the second column in the index, it can not be used). The field you are referencing in a foreign key always should be indexed.
In my case the issue was more like what was described in the first article you've linked to.
So I just had to make sure that:
Referenced Column is an index,
both Referencing Column and Referenced Column share the same type and length, i.e. e.g. both are INT(10),
both share the same not null, unsigned, zerofill etc. configuration.
both tables are InnoDB!
Here's the query template where Referencing Column is referencing_id and Referenced Column is referenced_id:
ALTER TABLE `db`.`referencing`
ADD CONSTRAINT `my_fk_idx`
FOREIGN KEY (`referencing_id`)
REFERENCES `db`.`referenced`(`referenced_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;
Update 2016-03-13: Ran into this problem again, ended up finding my own answer. This time it didn't help though. Turns out the other table was still set to MyISAM, as soon as I changed it to InnoDB everything worked.
This is the sql script I used to create a table in MS Access Database.
CREATE TABLE Contracts (
id int NULL DEFAULT 0,
sex varchar(255) DEFAULT 'female' NOT NULL
)
Now I want to programmatically get the default value of the field: "sex", I know it's 'female' but I don't know how to get it using C++ ADO interface.
Below is a snippet of my code:
m_pRecordset->Fields->get_Item(vIntegerType, &pvObject);
bstrColName = pvObject->GetName();
dtype = pvObject->GetType();
attr = pvObject->GetAttributes();
I can give you idea how to achieve it..
GetAttributes() method will not give you default value of the field but it will give you info about whether field is autoincrement ,system field or fixed - variable size field.
Check out for method GetDefaultValue() of the field that will do what you want.